package cn.stylefeng.guns.modular.ry600.controller;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;

//import net.sf.jasperreports.engine.JRDataSource;
//import net.sf.jasperreports.engine.JRException;
//import net.sf.jasperreports.engine.JRExporterParameter;
//import net.sf.jasperreports.engine.JasperFillManager;
//import net.sf.jasperreports.engine.JasperPrint;
//import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
//import net.sf.jasperreports.engine.export.JRPdfExporter;



































import jxl.read.biff.BiffException;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.core.util.CacheUtil;
import cn.stylefeng.guns.core.util.ExcellUtil;
import cn.stylefeng.guns.core.util.ServerResponse;
import cn.stylefeng.guns.modular.ry600.controller.exception.NotAuthedException;
import cn.stylefeng.guns.modular.ry600.service.IBackOrderItemService;
import cn.stylefeng.guns.modular.ry600.service.IBackOrderService;
import cn.stylefeng.guns.modular.ry600.service.ICheckService;
import cn.stylefeng.guns.modular.ry600.service.IClientService;
import cn.stylefeng.guns.modular.ry600.service.IClientcustomerService;
import cn.stylefeng.guns.modular.ry600.service.IClientproductService;
import cn.stylefeng.guns.modular.ry600.service.ICommonService;
import cn.stylefeng.guns.modular.ry600.service.IErpCustomerService;
import cn.stylefeng.guns.modular.ry600.service.IErpProductPriceService;
import cn.stylefeng.guns.modular.ry600.service.IErpProductService;
import cn.stylefeng.guns.modular.ry600.service.IErpProductStockService;
import cn.stylefeng.guns.modular.ry600.service.IErpkindService;
import cn.stylefeng.guns.modular.ry600.service.IOrderService;
import cn.stylefeng.guns.modular.ry600.service.IOrdercheckService;
import cn.stylefeng.guns.modular.ry600.service.IOrderitemService;
import cn.stylefeng.guns.modular.ry600.service.IOutOrderItemService;
import cn.stylefeng.guns.modular.ry600.service.IOutOrderService;
import cn.stylefeng.guns.modular.ry600.service.IReviseOrderService;
import cn.stylefeng.guns.modular.ry600.service.impl.ReviseOrderItemServiceImpl;
import cn.stylefeng.guns.modular.system.dao.OrdercheckMapper;
import cn.stylefeng.guns.modular.system.model.BackOrder;
import cn.stylefeng.guns.modular.system.model.BackOrderItem;
import cn.stylefeng.guns.modular.system.model.Client;
import cn.stylefeng.guns.modular.system.model.ClientCheck;
import cn.stylefeng.guns.modular.system.model.Clientcustomer;
import cn.stylefeng.guns.modular.system.model.Clientproduct;
import cn.stylefeng.guns.modular.system.model.ErpCustomer;
import cn.stylefeng.guns.modular.system.model.ErpProduct;
import cn.stylefeng.guns.modular.system.model.ErpProductPrice;
import cn.stylefeng.guns.modular.system.model.ErpProductStock;
import cn.stylefeng.guns.modular.system.model.Erpkind;
import cn.stylefeng.guns.modular.system.model.Order;
import cn.stylefeng.guns.modular.system.model.Ordercheck;
import cn.stylefeng.guns.modular.system.model.Orderitem;
import cn.stylefeng.guns.modular.system.model.OutOrder;
import cn.stylefeng.guns.modular.system.model.OutOrderItem;
import cn.stylefeng.guns.modular.system.model.OutOrderItemRe;
import cn.stylefeng.guns.modular.system.model.ResponseData;
import cn.stylefeng.guns.modular.system.model.ReviseOrder;
import cn.stylefeng.guns.modular.system.model.ReviseOrderItem;
import cn.stylefeng.guns.modular.system.model.ReviseOrderItemRe;
import cn.stylefeng.guns.modular.system.model.TestWater;
import cn.stylefeng.roses.core.base.controller.BaseController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

@Controller
@RequestMapping("/oauth")
public class OauthController extends BaseController {
	
	Map<String, Map<String, String>> rela = new HashMap<String, Map<String, String>>();

	@Autowired
	private IClientService clientService;
	@Autowired
	private IErpkindService erpkindService;
	@Autowired
	private IErpProductService erpProductService;
	@Autowired
	private IErpCustomerService erpcustomerService;
	@Autowired
	private IClientcustomerService clientcustomerService;
	@Autowired
	private IClientproductService clientproductService;
	@Autowired
	private IErpProductPriceService erpProductPriceService;
	@Autowired
	private IErpProductStockService erpProductStockService;
	@Autowired
	private IOrderService orderService;
	@Autowired
	private IOrderitemService orderitemService;
	@Autowired
	private IReviseOrderService iReviseOrderService;
	@Autowired
	private ReviseOrderItemServiceImpl reviseOrderItemServiceImpl;
	@Autowired
	private IOutOrderService outOrderService;
	@Autowired
	private IOutOrderItemService outOrderItemService;
	@Autowired
	private IBackOrderService backOrderService;
	@Autowired
	private IBackOrderItemService backOrderItemService;
	@Autowired
	private ICheckService checkService;
	@Autowired
	private IOrdercheckService ordercheckService;
	
	@Autowired
	private OrdercheckMapper ordercheckMapper;
	
	@Autowired
	private ICommonService commonService;

	// @RequestMapping("/token")
	// @ResponseBody
	// public Object token(@RequestBody ClientCheck clientCheck){
	// Map<String ,Object> returnToken=clientService.checkToken(clientCheck);
	// if(returnToken==null){
	// return ServerResponse.createByErrorMessage("客户不存在");
	// }else{
	// return returnToken;
	// }
	//
	// }
	// @RequestMapping("/token")
	@ResponseBody
	@PostMapping("/token")
	public Object token(@RequestParam(required = false) String grant_type,
			@RequestParam(required = false) String client_id,
			@RequestParam(required = false) String client_secret) {
		ClientCheck clientCheck = new ClientCheck();
		clientCheck.setClient_id(client_id);
		clientCheck.setClient_secret(client_secret);
		clientCheck.setGrant_type(grant_type);
		Map<String, Object> returnToken = checkService.checkToken(clientCheck);
		if (returnToken == null) {
			return ServerResponse.createByErrorMessage("客户不存在");
		} else {
			System.out.println("returnToken:" + returnToken);
			return returnToken;
		}

	}
	
	public void checkClient(String clientId){
		Map<String,Object> msg=new HashMap<String,Object>();
		msg.put("clientId", clientId);
		List<Client> cl=(List<Client>) clientService.selectByMsg(msg);
		if(cl.size()==0){
			throw  new NotAuthedException("连锁账号不存在");
		}
		if(!"0".equals(cl.get(0).getClientState())){
			throw  new NotAuthedException("连锁未启用");
		}
	}


	@GetMapping("/getProductTest")
	@ResponseBody
	public Object getProductTest(@RequestParam(required = false) String page,
			@RequestParam(required = false) String num,
			@RequestParam(required = false) String editDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 String temp
		 * = CacheUtil.get(transToken, transToken);
		 * System.out.println("transToken:" + transToken);
		 * System.out.println("temp:" + temp); if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); //
		 * ResponseErrorToken rt=new ResponseErrorToken(); //
		 * rt.setError_description("Invalid access token:"+transToken); //
		 * return rt; throw new AuthenticationException("未登录"); } else {
		 */
		/*
		 * 获取日期条件
		 */
		Map<String, Object> productsMsg = new HashMap<String, Object>();
		if (!StringUtils.isBlank(editDate)) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			try {
				productsMsg.put("lastDate", sdf.parse(editDate));
			} catch (ParseException e) {
				throw new AuthenticationException("传入日期格式错误");
			}
		}

		if (StringUtils.isBlank(page) || StringUtils.isBlank(num)
				|| Integer.parseInt(page) < 1 || Integer.parseInt(num) < 1) {
			/*
			 * 没有页码传入，分批获取所有的数据
			 */
			// 获取账套信息
			List<Erpkind> resultErpKind = erpkindService.selectList(null);
			// 所有商品信息
			List<ErpProduct> allProduct = new ArrayList<ErpProduct>();
			Set<String> dataSource = new HashSet<String>();
			for (int i = 0; i < resultErpKind.size(); i++) {
				// productsMsg.put("token", "gfjgklfdkjglfd");
				if (dataSource.add(resultErpKind.get(i).getDataSource())) {
					// int passCount=erpProductService.passDate(productsMsg,
					// resultErpKind.get(i)
					// .getDataSource());
					// 获取条目数
					int allCount = erpProductService.getCount(productsMsg,
							resultErpKind.get(i).getDataSource());
					for (int j = 1; j <= allCount / 1000 + 1; j++) {
						PageHelper.startPage(j, 1000);
						List<ErpProduct> products = (List<ErpProduct>) erpProductService
								.selectByMsg(productsMsg, resultErpKind.get(i)
										.getDataSource());
						allProduct.addAll(products);

					}
				}
			}

			ResponseData rd = new ResponseData();
			rd.setTotal(allProduct.size());
			rd.setRows((ArrayList) allProduct);
			// System.out.println(JSON.toJSONString(rd));

			// System.out.println(request.getHeader("Authorization"));
			// System.out.println(request.getHeader("client_id"));
			return ServerResponse.createBySuccess("获取商品成功", rd);

		} else {
			/*
			 * 有页码传入，按照页码获取数据
			 */
			int tempPage = Integer.parseInt(page);
			int tempNum = Integer.parseInt(num);
			// 获取当前页码前面的条目数
			int preCount = (tempPage - 1) * tempNum;
			// 获取账套信息
			List<Erpkind> resultErpKind = erpkindService.selectList(null);
			// 所有商品信息
			List<ErpProduct> allProduct = new ArrayList<ErpProduct>();
			Set<String> dataSource = new HashSet<String>();
			int point = 1;
			for (int i = 0; i < resultErpKind.size(); i++) {
				// productsMsg.put("token", "gfjgklfdkjglfd");
				if (dataSource.add(resultErpKind.get(i).getDataSource())
						&& point == 1) {
					// int passCount=erpProductService.passDate(productsMsg,
					// resultErpKind.get(i)
					// .getDataSource());

					// 获取条目数
					int allCount = erpProductService.getCount(productsMsg,
							resultErpKind.get(i).getDataSource());
					/*
					 * 判断当前数据库获取的条目数是否比当前页码获取到的条目数达，如果不满足条件则减掉当前数据库的总条目数然后跳过该数据库
					 */
					if ((preCount - allCount) > 0) {
						preCount = (preCount - allCount);
						break;
					}
					/*
					 * 当前数据库能够获取的数据量
					 */
					int plexCount = preCount - allCount;
					/*
					 * 如果一页的条目数比当前数据库剩余的条目数大则获取所有的数据
					 */
					if ((tempNum + plexCount) >= 0) {
						// 获取当前数据库被忽略的数据1000的倍数
						int n1 = (allCount + plexCount) / 1000;
						int n2 = (1000 * n1);
						int n3 = (allCount + plexCount) - n2;

						for (int j = n1; j <= allCount / 1000 + 1; j++) {
							PageHelper.startPage(j, 1000);
							List<ErpProduct> products = (List<ErpProduct>) erpProductService
									.selectByMsg(productsMsg, resultErpKind
											.get(i).getDataSource());
							if (n3 > 0) {
								for (int x = n3; x > 0; x--) {
									products.remove(x);
								}
							}
							tempNum = tempNum - products.size();
							preCount = 0;
							allProduct.addAll(products);
						}
					} else {

						// 获取当前数据库被忽略的数据1000的倍数
						int n1 = (allCount + plexCount) / 1000;
						int n2 = (1000 * n1);
						int n3 = (allCount + plexCount) - n2;

						int m1 = (allCount + tempNum + plexCount) / 1000;
						int m2 = 1000 * (m1 + 1);
						int m3 = 0;

						if (m2 > allCount) {
							m3 = tempNum + plexCount;
						} else {
							m3 = m2 - (allCount + tempNum + plexCount);
						}

						for (int j = n1; j <= m1 + 1; j++) {
							PageHelper.startPage(j, 1000);
							List<ErpProduct> products = (List<ErpProduct>) erpProductService
									.selectByMsg(productsMsg, resultErpKind
											.get(i).getDataSource());
							int m4 = products.size();
							if (m3 > 0) {
								for (int x = m4; x > m4 - m3; x--) {
									allProduct.remove(x);
								}
							}
							if (n3 > 0) {
								for (int x = n3; x > 0; x--) {
									products.remove(x);
								}
							}
							allProduct.addAll(products);

						}
						point = 0;
						/*
						 * 当前数据库的条目数满足传进页面前面的条目数时候开始获取数据
						 * 1、判断传进来的一页是否大于1000，如果大于一千则需要拆分进行获取
						 * 
						 * 
						 * for(int j=1;j<=allCount/1000+1;j++){
						 * PageHelper.startPage(j,1000); List<ErpProduct>
						 * products = (List<ErpProduct>) erpProductService
						 * .selectByMsg(productsMsg, resultErpKind.get(i)
						 * .getDataSource()); allProduct.addAll(products);
						 * 
						 * }
						 */
					}
				}
			}
			ResponseData rd = new ResponseData();
			rd.setTotal(allProduct.size());
			rd.setRows((ArrayList) allProduct);
			// System.out.println(JSON.toJSONString(rd));

			// System.out.println(request.getHeader("Authorization"));
			// System.out.println(request.getHeader("client_id"));
			return ServerResponse.createBySuccess("获取商品成功", rd);

		}
		// }

	}

	@GetMapping("/getProduct")
	@ResponseBody
	public Object getProduct(@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		
		  String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); // 判断token是否合法 
		  String temp= CacheUtil.get(transToken, transToken);
		  System.out.println("transToken:" + transToken);
		  System.out.println("temp:" + temp); 
		if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  	
			 /* ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  ResponseErrorToken rt=new ResponseErrorToken(); 
			  rt.setError_description("Invalid access token:"+transToken); 
			  return rt; */
			  throw new AuthenticationException("未登录"); 
		} else {
		this.checkClient(clientId);
		System.out.println(pageNum);
		// 默认页码
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		// 如果传入页码则更新页码
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}
		int preCount = (num - 1) * page;
		// 如果传入时间条件则封装时间格式参数
		Map<String, Object> productsMsg = new HashMap<String, Object>();
		if (!StringUtils.isBlank(lastDate)) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			try {
				productsMsg.put("lastDate", sdf.parse(lastDate));
			} catch (ParseException e) {
				throw new NotAuthedException("传入日期格式错误");
			}
		}
		// 获取账套信息
		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		// 所有商品信息
		List<ErpProduct> allProduct = new ArrayList<ErpProduct>();
		Set<String> dataSource = new HashSet<String>();
		for (int i = 0; i < resultErpKind.size(); i++) {
			// productsMsg.put("token", "gfjgklfdkjglfd");
			// 判断数据库是否已经被使用，能够正常添加的则未被使用
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				// int passCount=erpProductService.passDate(productsMsg,
				// resultErpKind.get(i)
				// .getDataSource());
				/*
				 * int allCount=erpProductService.getCount(productsMsg,
				 * resultErpKind.get(i) .getDataSource()); for(int
				 * j=1;j<=allCount/1000+1;j++){ PageHelper.startPage(j,1000);
				 * List<ErpProduct> products = (List<ErpProduct>)
				 * erpProductService .selectByMsg(productsMsg,
				 * resultErpKind.get(i) .getDataSource());
				 * allProduct.addAll(products);
				 * 
				 * }
				 */
				// 获取条目数
				int allCount = erpProductService.getCount(productsMsg,
						resultErpKind.get(i).getDataSource());
				System.out.println(allCount);
				// 记录下当前数据库的所有符合条件的总条目数
				total += allCount;
				if (preCount >= allCount) {
					preCount = preCount - allCount;
					continue;
				}
				if (allProduct.size() == maxPage) {
					continue;
				}
				// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
				if ((preCount + page) >= allCount) {
					productsMsg.put("beginNum", preCount + 1);
					productsMsg.put("endNum", allCount);
					List<ErpProduct> products = (List<ErpProduct>) erpProductService
							.selectByMsg(productsMsg, resultErpKind.get(i)
									.getDataSource());
					allProduct.addAll(products);
					page = preCount + page - allCount;
					preCount = 0;
				} else {
					productsMsg.put("beginNum", preCount + 1);
					productsMsg.put("endNum", preCount + page);
					List<ErpProduct> products = (List<ErpProduct>) erpProductService
							.selectByMsg(productsMsg, resultErpKind.get(i)
									.getDataSource());
					allProduct.addAll(products);
				}
				/*
				 * for (int o = 1; o <= allCount / 1000 + 1; o++) {
				 * productsMsg.put("beginNum", 2); productsMsg.put("endNum", 5);
				 * // PageHelper.startPage(o, 1000); List<ErpProduct> products =
				 * (List<ErpProduct>) erpProductService.selectByMsg(productsMsg,
				 * resultErpKind.get(i).getDataSource()); for(int
				 * n=preCount;n<products.size()-1;n++){
				 * if(allProduct.size()>=100){ break; }
				 * allProduct.add(products.get(n)); } }
				 */
				/*
				 * if (allCount > 100 * (num - 1) && page > 0) {
				 * PageHelper.startPage(num, page); List<ErpProduct> products =
				 * (List<ErpProduct>) erpProductService
				 * .selectByMsg(productsMsg, resultErpKind.get(i)
				 * .getDataSource()); page = page - products.size(); num = 1;
				 * allProduct.addAll(products); } else { num = num - allCount /
				 * 100; }
				 */
			}
		}

		ResponseData rd = new ResponseData();
		/*if (total % 100 > 0) {
			rd.setTotal((total / 100) + 1);
		} else {
			rd.setTotal(total / 100);
		}*/
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allProduct);
		// System.out.println(JSON.toJSONString(rd));

		// System.out.println(request.getHeader("Authorization"));
		// System.out.println(request.getHeader("client_id"));
		return ServerResponse.createBySuccess("获取商品成功", rd);
		 }

	}

	@GetMapping("/getOrg")
	@ResponseBody
	public Object getOrg(@RequestParam(required = false) String orgId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		
		  String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		this.checkClient(clientId);
		System.out.println(pageNum);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}

		int preCount = (num - 1) * page;

		Map<String, Object> orgMsg = new HashMap<String, Object>();

		// 获取账套信息
		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		// 所有客户信息
		List<ErpCustomer> allOrg = new ArrayList<ErpCustomer>();
		Set<String> dataSource = new HashSet<String>();
		for (int i = 0; i < resultErpKind.size(); i++) {
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				orgMsg.put("clientId", clientId);
				if (!StringUtils.isBlank(orgId)) {

					orgMsg.put("orgId", orgId);
				}
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				int clientCount = clientcustomerService.getCount(orgMsg);
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				for (int u = 1; u <= clientCount / 1000 + 1; u++) {
					PageHelper.startPage(u, 1000);
					List<Clientcustomer> clientcustomer = (List<Clientcustomer>) clientcustomerService
							.selectByMsg(orgMsg);
					List<String> clientList = new ArrayList<String>();
					for (int j = 0; j < clientcustomer.size(); j++) {
						clientList.add(clientcustomer.get(j).getOrgId());
					}
					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientcustomer");
						orgMsg.put("clientList", clientList);
					}
					if (!StringUtils.isBlank(lastDate)) {
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss");

						try {
							orgMsg.put("lastDate", sdf.parse(lastDate));
						} catch (ParseException e) {
							throw new NotAuthedException("传入日期格式错误");
						}
					}
					int allCount = erpcustomerService.getCount(orgMsg,
							resultErpKind.get(i).getDataSource());
					total += allCount;
					if (preCount > allCount) {
						preCount = preCount - allCount;
						continue;
					}
					if (allOrg.size() == maxPage) {
						continue;
					}

					// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
					if ((preCount + page) >= allCount) {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", allCount);
						List<ErpCustomer> orgs = (List<ErpCustomer>) erpcustomerService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
						page = preCount + page - allCount;
						preCount = 0;
					} else {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", preCount + page);
						List<ErpCustomer> orgs = (List<ErpCustomer>) erpcustomerService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
					}

					/*
					 * for (int o = 1; o <= allCount / 1000 + 1; o++) {
					 * PageHelper.startPage(o, 1000); List<ErpCustomer> orgs =
					 * (List<ErpCustomer>) erpcustomerService
					 * .selectByMsg(orgMsg, resultErpKind.get(i)
					 * .getDataSource()); if (allCount > 0) {
					 * 
					 * for (int p = preCount; p <= orgs.size() - 1; p++) { if
					 * (allOrg.size() == 100) { break; }
					 * allOrg.add(orgs.get(p)); } }
					 * 
					 * }
					 */
				}
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(total / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrg);
		System.out.println(JSON.toJSONString(rd));

		// System.out.println(request.getHeader("Authorization"));
		// System.out.println(request.getHeader("client_id"));
		return ServerResponse.createBySuccess("获取客户成功", rd);
		 }
	}

	@GetMapping("/getBackOrder")
	@ResponseBody
	public Object getBackOrder(@RequestParam(required = false) String orgId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		
		 String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		this.checkClient(clientId);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;

		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}
		Map<String, Object> orgMsg = new HashMap<String, Object>();
		if (!StringUtils.isBlank(lastDate)) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			try {
				orgMsg.put("lastDate", sdf.parse(lastDate));
			} catch (ParseException e) {
				throw new NotAuthedException("传入日期格式错误");
			}
		}

		int preCount = (num - 1) * 100;

		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		Set<String> dataSource = new HashSet<String>();
		List<String> clientList = new ArrayList<String>();

		List<BackOrder> allOrd = new ArrayList<BackOrder>();
		Map<String, Object> allOrderPoint = new HashMap<String, Object>();
		List<String> ordList = new ArrayList<String>();

		orgMsg.put("clientId", clientId);

		if (!StringUtils.isBlank(orgId)) {

			orgMsg.put("orgId", orgId);
		}
		for (int h = 0; h < resultErpKind.size(); h++) {
			if (dataSource.add(resultErpKind.get(h).getDataSource())) {
				orgMsg.put("dataType", resultErpKind.get(h).getAccountId());
				int clientcus = clientcustomerService.getCount(orgMsg);
				orgMsg.put("dataType", resultErpKind.get(h).getAccountId());
				for (int j = 1; j <= clientcus / 1000 + 1; j++) {
					PageHelper.startPage(j, 1000);
					List<Clientcustomer> clientcustomer = (List<Clientcustomer>) clientcustomerService
							.selectByMsg(orgMsg);
					for (int k = 0; k < clientcustomer.size(); k++) {
						clientList.add(clientcustomer.get(k).getOrgId());
					}
					/*
					 * if (clientList.size() > 0) { orgMsg.put("clientList",
					 * clientList); } else {
					 * clientList.add("clientproductprice");
					 * orgMsg.put("clientList", clientList); }
					 */

					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientproductprice");
						orgMsg.put("clientList", clientList);
					}
					if (!StringUtils.isBlank(lastDate)) {
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss");

						try {
							orgMsg.put("lastDate", sdf.parse(lastDate));
						} catch (ParseException e) {
							throw new NotAuthedException("传入日期格式错误");
						}
					}
					int allCount = backOrderService.getCount(orgMsg,
							resultErpKind.get(h).getDataSource());
					total += allCount;
					if (preCount >= allCount) {
						preCount = preCount - allCount;
						continue;
					}

					if (allOrd.size() == maxPage) {
						continue;
					}

					// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
					if ((preCount + page) >= allCount) {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", allCount);
						List<BackOrder> bol = (List<BackOrder>) backOrderService
								.selectByMsg(orgMsg, resultErpKind.get(h)
										.getDataSource());
						for (int o = 0; o < bol.size(); o++) {
							if (!allOrderPoint.containsKey(bol.get(o)
									.getBillId())) {
								allOrd.add(bol.get(o));
								allOrderPoint.put(bol.get(o).getBillId(),
										allOrd.size() - 1);
								ordList.add(bol.get(o).getBillId());
							}

						}
						if (ordList.size() > 0) {
							orgMsg.put("ordList", ordList);
						
						
						
						
						List<BackOrderItem> roil = (List<BackOrderItem>) backOrderItemService
								.selectByMsg(orgMsg, resultErpKind.get(h)
										.getDataSource());
						for (int x = 0; x < roil.size(); x++) {
							if (allOrd.get(
									(int) allOrderPoint.get(roil.get(x)
											.getBillId())).getBoi() == null) {
								List<BackOrderItem> roitemp = new ArrayList<BackOrderItem>();
								roitemp.add(roil.get(x));
								allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).setBoi(roitemp);
							} else {
								List<BackOrderItem> roitemp = new ArrayList<BackOrderItem>();
								roitemp.addAll(allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).getBoi());
								roitemp.add(roil.get(x));
								allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).setBoi(roitemp);
							}

						}

						page = preCount + page - allCount;
						preCount = 0;
						}
						/*} else {
							ordList.add("clientproductprice");
							orgMsg.put("ordList", ordList);
						}*/
					} else {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", preCount + page);
						List<BackOrder> bol = (List<BackOrder>) backOrderService
								.selectByMsg(orgMsg, resultErpKind.get(h)
										.getDataSource());
						for (int o = 0; o < bol.size(); o++) {
							if (!allOrderPoint.containsKey(bol.get(o)
									.getBillId())) {
								allOrd.add(bol.get(o));
								allOrderPoint.put(bol.get(o).getBillId(),
										allOrd.size() - 1);
								ordList.add(bol.get(o).getBillId());
							}

						}
						if (ordList.size() > 0) {
							orgMsg.put("ordList", ordList);
						

						List<BackOrderItem> roil = (List<BackOrderItem>) backOrderItemService
								.selectByMsg(orgMsg, resultErpKind.get(h)
										.getDataSource());
						for (int x = 0; x < roil.size(); x++) {
							if (allOrd.get(
									(int) allOrderPoint.get(roil.get(x)
											.getBillId())).getBoi() == null) {
								List<BackOrderItem> roitemp = new ArrayList<BackOrderItem>();
								roitemp.add(roil.get(x));
								allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).setBoi(roitemp);
							} else {
								List<BackOrderItem> roitemp = new ArrayList<BackOrderItem>();
								roitemp.addAll(allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).getBoi());
								roitemp.add(roil.get(x));
								allOrd.get(
										(int) allOrderPoint.get(roil.get(x)
												.getBillId())).setBoi(roitemp);
							}

						}
						
						}
						/*else {
							ordList.add("clientproductprice");
							orgMsg.put("ordList", ordList);
						}*/
					}

				}
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(allOrd.size() / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrd);

		System.out.println(allOrd.toString());
		return ServerResponse.createBySuccess("获取退货单成功", rd);
		 }
	}

	@GetMapping("/getProductPrice")
	@ResponseBody
	public Object getProductPrice(
			@RequestParam(required = false) String productId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		 String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		this.checkClient(clientId);
		System.out.println(pageNum);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}

		int preCount = (num - 1) * page;

		Map<String, Object> orgMsg = new HashMap<String, Object>();

		// 获取账套信息
		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		// 所有客户信息
		List<ErpProductPrice> allOrg = new ArrayList<ErpProductPrice>();
		Set<String> dataSource = new HashSet<String>();
		for (int i = 0; i < resultErpKind.size(); i++) {
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				orgMsg.put("clientId", clientId);
				if (!StringUtils.isBlank(productId)) {

					orgMsg.put("productId", productId);
				}
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				int clientCount = clientproductService.getCount(orgMsg);
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				for (int u = 1; u <= clientCount / 1000 + 1; u++) {
					PageHelper.startPage(u, 1000);
					List<Clientproduct> clientcustomer = (List<Clientproduct>) clientproductService
							.selectByMsg(orgMsg);
					List<String> clientList = new ArrayList<String>();
					for (int j = 0; j < clientcustomer.size(); j++) {
						clientList.add(clientcustomer.get(j).getProductId());
					}
					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientcustomer");
						orgMsg.put("clientList", clientList);
					}
					if (!StringUtils.isBlank(lastDate)) {
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss");

						try {
							orgMsg.put("lastDate", sdf.parse(lastDate));
						} catch (ParseException e) {
							throw new NotAuthedException("传入日期格式错误");
						}
					}
					int allCount = erpProductPriceService.getCount(orgMsg,
							resultErpKind.get(i).getDataSource());
					total += allCount;
					if (preCount > allCount) {
						preCount = preCount - allCount;
						continue;
					}

					if (allOrg.size() == maxPage) {
						continue;
					}

					// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
					if ((preCount + page) >= allCount) {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", allCount);
						List<ErpProductPrice> orgs = (List<ErpProductPrice>) erpProductPriceService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
						page = preCount + page - allCount;
						preCount = 0;
					} else {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", preCount + page);
						List<ErpProductPrice> orgs = (List<ErpProductPrice>) erpProductPriceService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
					}

					/*
					 * for (int o = 1; o <= allCount / 1000 + 1; o++) {
					 * PageHelper.startPage(o, 1000); List<ErpProductPrice> orgs
					 * = (List<ErpProductPrice>) erpProductPriceService
					 * .selectByMsg(orgMsg, resultErpKind.get(i)
					 * .getDataSource()); if (allCount > 0) {
					 * 
					 * for (int p = preCount; p <= orgs.size() - 1; p++) { if
					 * (allOrg.size() == 100) { break; }
					 * allOrg.add(orgs.get(p)); } }
					 * 
					 * }
					 */
				}
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(total / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrg);
		System.out.println(JSON.toJSONString(rd));

		// System.out.println(request.getHeader("Authorization"));
		// System.out.println(request.getHeader("client_id"));
		return ServerResponse.createBySuccess("获取商品价格成功", rd);
		 }
	}

	/*
	 * @GetMapping("/getProductPrice")
	 * 
	 * @ResponseBody public Object getProductPrice(
	 * 
	 * @RequestParam(required = false) String productId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else {
	 * 
	 * 
	 * int num = 1; int page = 100; int total = 0; if
	 * (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num =
	 * Integer.parseInt(pageNum); } Map<String, Object> orgMsg = new
	 * HashMap<String, Object>(); if (!StringUtils.isBlank(lastDate)) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * 
	 * // 获取账套信息 List<Erpkind> resultErpKind = erpkindService.selectList(null);
	 * // 所有商品信息 List<ErpProductPrice> allProductPrice = new
	 * ArrayList<ErpProductPrice>(); Set<String> dataSource = new
	 * HashSet<String>(); for (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * orgMsg.put("clientId", "guorenclient"); if
	 * (!StringUtils.isBlank(productId)) {
	 * 
	 * orgMsg.put("productId", productId); } orgMsg.put("dataType",
	 * resultErpKind.get(i).getAccountId()); PageHelper.startPage(num, page);
	 * List<Clientproduct> clientproduct = (List<Clientproduct>)
	 * clientproductService .selectByMsg(orgMsg); List<String> clientList = new
	 * ArrayList<String>(); for (int j = 0; j < clientproduct.size(); j++) {
	 * clientList.add(clientproduct.get(j).getProductId()); }
	 * PageHelper.startPage(num + 1, page); List<Clientproduct> clientproduct1 =
	 * (List<Clientproduct>) clientproductService .selectByMsg(orgMsg); for (int
	 * j = 0; j < clientproduct1.size(); j++) {
	 * clientList.add(clientproduct1.get(j).getProductId()); } orgMsg.clear();
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); } int allCount = erpProductPriceService.getCount(orgMsg,
	 * resultErpKind.get(i).getDataSource()); total += allCount; if (allCount >
	 * 100 * (num - 1) && page > 0) { List<ErpProductPrice> productPrices =
	 * (List<ErpProductPrice>) erpProductPriceService .selectByMsg(orgMsg,
	 * resultErpKind.get(i) .getDataSource());
	 * allProductPrice.addAll(productPrices); page = page -
	 * productPrices.size(); num = 1;
	 * 
	 * } else { num = num - allCount / 100; } } }
	 * 
	 * ResponseData rd = new ResponseData(); if (total % 100 > 0) {
	 * rd.setTotal((total / 100) + 1); } else { rd.setTotal(total / 100); }
	 * rd.setRows((ArrayList) allProductPrice);
	 * System.out.println(JSON.toJSONString(rd));
	 * 
	 * // System.out.println(request.getHeader("Authorization")); //
	 * System.out.println(request.getHeader("client_id")); return
	 * ServerResponse.createBySuccess("获取商品价格成功", rd); // }
	 * 
	 * }
	 */

	@GetMapping("/getProductStock")
	@ResponseBody
	public Object getProductStock(
			@RequestParam(required = false) String productId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		
		 String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		
		this.checkClient(clientId);
		System.out.println(pageNum);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}

		int preCount = (num - 1) * page;

		Map<String, Object> orgMsg = new HashMap<String, Object>();

		// 获取账套信息
		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		// 所有客户信息
		List<ErpProductStock> allOrg = new ArrayList<ErpProductStock>();
		Set<String> dataSource = new HashSet<String>();
		for (int i = 0; i < resultErpKind.size(); i++) {
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				orgMsg.put("clientId", clientId);
				if (!StringUtils.isBlank(productId)) {

					orgMsg.put("productId", productId);
				}
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				int clientCount = clientproductService.getCount(orgMsg);
				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				for (int u = 1; u <= clientCount / 1000 + 1; u++) {
					PageHelper.startPage(u, 1000);
					List<Clientproduct> clientcustomer = (List<Clientproduct>) clientproductService
							.selectByMsg(orgMsg);
					List<String> clientList = new ArrayList<String>();
					for (int j = 0; j < clientcustomer.size(); j++) {
						clientList.add(clientcustomer.get(j).getProductId());
					}
					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientcustomer");
						orgMsg.put("clientList", clientList);
					}
					if (!StringUtils.isBlank(lastDate)) {
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss");

						try {
							orgMsg.put("lastDate", sdf.parse(lastDate));
						} catch (ParseException e) {
							throw new NotAuthedException("传入日期格式错误");
						}
					}
					int allCount = erpProductStockService.getCount(orgMsg,
							resultErpKind.get(i).getDataSource());
					total += allCount;
					if (preCount > allCount) {
						preCount = preCount - allCount;
						continue;
					}

					if (allOrg.size() == maxPage) {
						continue;
					}

					// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
					if ((preCount + page) >= allCount) {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", allCount);
						List<ErpProductStock> orgs = (List<ErpProductStock>) erpProductStockService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
						page = preCount + page - allCount;
						preCount = 0;
					} else {
						orgMsg.put("beginNum", preCount + 1);
						orgMsg.put("endNum", preCount + page);
						List<ErpProductStock> orgs = (List<ErpProductStock>) erpProductStockService
								.selectByMsg(orgMsg, resultErpKind.get(i)
										.getDataSource());
						allOrg.addAll(orgs);
					}

					/*
					 * for (int o = 1; o <= allCount / 1000 + 1; o++) {
					 * PageHelper.startPage(o, 1000); List<ErpProductStock> orgs
					 * = (List<ErpProductStock>) erpProductStockService
					 * .selectByMsg(orgMsg, resultErpKind.get(i)
					 * .getDataSource()); if (allCount > 0) {
					 * 
					 * for (int p = preCount; p <= orgs.size() - 1; p++) { if
					 * (allOrg.size() == 100) { break; }
					 * allOrg.add(orgs.get(p)); } }
					 * 
					 * }
					 */
				}
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(total / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrg);
		System.out.println(JSON.toJSONString(rd));

		// System.out.println(request.getHeader("Authorization"));
		// System.out.println(request.getHeader("client_id"));
		return ServerResponse.createBySuccess("获取商品库存成功", rd);
		 }
	}

	/*
	 * @GetMapping("/getProductStock")
	 * 
	 * @ResponseBody public Object getProductStock(
	 * 
	 * @RequestParam(required = false) String productId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else { // 获取账套信息
	 * 
	 * int num = 1; int page = 100; int total = 0; if
	 * (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num =
	 * Integer.parseInt(pageNum); } Map<String, Object> orgMsg = new
	 * HashMap<String, Object>(); if (!StringUtils.isBlank(lastDate)) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * 
	 * List<Erpkind> resultErpKind = erpkindService.selectList(null); // 所有商品信息
	 * List<ErpProductStock> allProductStock = new ArrayList<ErpProductStock>();
	 * Set<String> dataSource = new HashSet<String>(); for (int i = 0; i <
	 * resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * orgMsg.put("clientId", "guorenclient");
	 * 
	 * if (!StringUtils.isBlank(productId)) {
	 * 
	 * orgMsg.put("productId", productId); }
	 * 
	 * orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
	 * 
	 * PageHelper.startPage(num, page); List<Clientproduct> clientproduct =
	 * (List<Clientproduct>) clientproductService .selectByMsg(orgMsg);
	 * List<String> clientList = new ArrayList<String>(); for (int j = 0; j <
	 * clientproduct.size(); j++) {
	 * clientList.add(clientproduct.get(j).getProductId()); }
	 * PageHelper.startPage(num + 1, page); List<Clientproduct> clientproduct1 =
	 * (List<Clientproduct>) clientproductService .selectByMsg(orgMsg); for (int
	 * j = 0; j < clientproduct1.size(); j++) {
	 * clientList.add(clientproduct1.get(j).getProductId()); }
	 * PageHelper.startPage(num + 2, page); List<Clientproduct> clientproduct2 =
	 * (List<Clientproduct>) clientproductService .selectByMsg(orgMsg); for (int
	 * j = 0; j < clientproduct2.size(); j++) {
	 * clientList.add(clientproduct2.get(j).getProductId()); }
	 * 
	 * orgMsg.clear(); if (clientList.size() > 0) { orgMsg.put("clientList",
	 * clientList); } else { clientList.add("clientproductprice");
	 * orgMsg.put("clientList", clientList); }
	 * 
	 * int allCount = erpProductStockService.getCount(orgMsg,
	 * resultErpKind.get(i).getDataSource()); total += allCount; if (allCount >
	 * 100 * (num - 1) && page > 0) {
	 * 
	 * List<ErpProductStock> orgs = (List<ErpProductStock>)
	 * erpProductStockService .selectByMsg(orgMsg, resultErpKind.get(i)
	 * .getDataSource()); allProductStock.addAll(orgs); page = page -
	 * orgs.size(); num = 1; } else { num = num - allCount / 100; } } }
	 * 
	 * ResponseData rd = new ResponseData(); if (total % 100 > 0) {
	 * rd.setTotal((total / 100) + 1); } else { rd.setTotal(total / 100); }
	 * rd.setRows((ArrayList) allProductStock);
	 * System.out.println(JSON.toJSONString(rd));
	 * 
	 * // System.out.println(request.getHeader("Authorization")); //
	 * System.out.println(request.getHeader("client_id")); return
	 * ServerResponse.createBySuccess("获取库存成功", rd); // }
	 * 
	 * }
	 */

	@PostMapping("/postOrder")
	@ResponseBody
	public Object postOrder(@RequestBody(required=false) Map<String,String> json,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		 
		
		
		String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		
		
		this.checkClient(clientId);
		/*Orderitem oi = new Orderitem();
		oi.setBillId("666666");
		oi.setItemId("1");
		oi.setProductId("X15314");
		oi.setGeneralName("阿莫西林胶囊");
		oi.setSpec("0.25g*20s");
		oi.setFactoryName("白云山制药总厂");
		oi.setOrigin("");
		oi.setApprovalNo("国药准字H245542252");
		oi.setUnit("盒");
		oi.setPrice((double) 10);
		oi.setAmount((double) 10);
		oi.setPayment((double) 100);

		Orderitem oi1 = new Orderitem();
		oi1.setBillId("666666");
		oi1.setItemId("2");
		oi1.setProductId("Z4347");
		oi1.setGeneralName("阿莫西林胶囊");
		oi1.setSpec("0.25g*20s");
		oi1.setFactoryName("白云山制药总厂");
		oi1.setOrigin("");
		oi1.setApprovalNo("国药准字H245542252");
		oi1.setUnit("盒");
		oi1.setPrice((double) 10);
		oi1.setAmount((double) 10);
		oi1.setPayment((double) 100);
		
		
		Orderitem oi2 = new Orderitem();
		oi2.setBillId("666666");
		oi2.setItemId("3");
		oi2.setProductId("X3096");
		oi2.setGeneralName("阿莫西林胶囊");
		oi2.setSpec("0.25g*20s");
		oi2.setFactoryName("白云山制药总厂");
		oi2.setOrigin("");
		oi2.setApprovalNo("国药准字H245542252");
		oi2.setUnit("盒");
		oi2.setPrice((double) 10);
		oi2.setAmount((double) 10);
		oi2.setPayment((double) 100);
		
		
		Orderitem oi3 = new Orderitem();
		oi3.setBillId("666666");
		oi3.setItemId("1");
		oi3.setProductId("X14432");
		oi3.setGeneralName("阿莫西林胶囊");
		oi3.setSpec("0.25g*20s");
		oi3.setFactoryName("白云山制药总厂");
		oi3.setOrigin("");
		oi3.setApprovalNo("国药准字H245542252");
		oi3.setUnit("盒");
		oi3.setPrice((double) 10);
		oi3.setAmount((double) 10);
		oi3.setPayment((double) 100);
		
		Orderitem oi4 = new Orderitem();
		oi4.setBillId("666666");
		oi4.setItemId("1");
		oi4.setProductId("X15513");
		oi4.setGeneralName("阿莫西林胶囊");
		oi4.setSpec("0.25g*20s");
		oi4.setFactoryName("白云山制药总厂");
		oi4.setOrigin("");
		oi4.setApprovalNo("国药准字H245542252");
		oi4.setUnit("盒");
		oi4.setPrice((double) 10);
		oi4.setAmount((double) 10);
		oi4.setPayment((double) 100);
		
		
		Orderitem oi5 = new Orderitem();
		oi5.setBillId("666666");
		oi5.setItemId("1");
		oi5.setProductId("X96");
		oi5.setGeneralName("阿莫西林胶囊");
		oi5.setSpec("0.25g*20s");
		oi5.setFactoryName("白云山制药总厂");
		oi5.setOrigin("");
		oi5.setApprovalNo("国药准字H245542252");
		oi5.setUnit("盒");
		oi5.setPrice((double) 10);
		oi5.setAmount((double) 10);
		oi5.setPayment((double) 100);*/
		
//		Orderitem oi = new Orderitem();
//		oi.setClientId("guoren");
//		oi.setBillId("lyytest");
//		oi.setItemId("1");
//		oi.setProductId("X15314");
//		oi.setGeneralName("阿莫西林胶囊");
//		oi.setSpec("0.25g*20s");
//		oi.setFactoryName("白云山制药总厂");
//		oi.setOrigin("");
//		oi.setApprovalNo("国药准字H245542252");
//		oi.setUnit("盒");
//		oi.setPrice((double) 10);
//		oi.setAmount((double) 10);
//		oi.setPayment((double) 100);
//
//		Orderitem oi1 = new Orderitem();
//		oi1.setClientId("guoren");
//		oi1.setBillId("lyytest");
//		oi1.setItemId("2");
//		oi1.setProductId("Z4347");
//		oi1.setGeneralName("阿莫西林胶囊");
//		oi1.setSpec("0.25g*20s");
//		oi1.setFactoryName("白云山制药总厂");
//		oi1.setOrigin("");
//		oi1.setApprovalNo("国药准字H245542252");
//		oi1.setUnit("盒");
//		oi1.setPrice((double) 10);
//		oi1.setAmount((double) 10);
//		oi1.setPayment((double) 100);
//		
//		
//		Orderitem oi2 = new Orderitem();
//		oi2.setClientId("guoren");
//		oi2.setBillId("lyytest");
//		oi2.setItemId("3");
//		oi2.setProductId("X3096");
//		oi2.setGeneralName("阿莫西林胶囊");
//		oi2.setSpec("0.25g*20s");
//		oi2.setFactoryName("白云山制药总厂");
//		oi2.setOrigin("");
//		oi2.setApprovalNo("国药准字H245542252");
//		oi2.setUnit("盒");
//		oi2.setPrice((double) 10);
//		oi2.setAmount((double) 10);
//		oi2.setPayment((double) 100);
//		
//
//		List<Orderitem> oil = new ArrayList<Orderitem>();
//		oil.add(oi);
//		oil.add(oi1);
//		oil.add(oi2);
////		oil.add(oi3);
////		oil.add(oi4);
////		oil.add(oi5);
//		Order od = new Order();
//		od.setClientId("guoren");
//		od.setBillId("lyytest");
//		od.setBillDate("2018-10-01");
//		od.setOrgId("X16");
//		od.setOrgName("testorgname");
//		od.setPayment((double) 100);
//		od.setOrderitem(oil);
//		String str = JSON.toJSONString(od);
//		System.out.println(str);
//
//		Order od1 = JSON.parseObject(str, Order.class);
		Order od1 = JSON.parseObject(json.get("json"), Order.class);
		od1.setClientId(clientId);
		
		String resultMsg=this.checkOrder(od1);
		
		Map<String,Object> msg=new HashMap<String,Object>();
		msg.put("clientId", od1.getClientId());
		msg.put("billId", od1.getBillId());
		if(orderService.getCount(msg)>0){
			throw new NotAuthedException("该订单重复推送");
		}else{
		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		Set<String> dataSource = new HashSet<String>();
		for (int i = 0; i < resultErpKind.size(); i++) {
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
					int order = orderService.insertOrder(od1, resultErpKind.get(i)
							.getDataSource());
					for (int j = 0; j < od1.getOrderitem().size(); j++) {
						Orderitem oi=od1.getOrderitem().get(j);
						oi.setClientId(clientId);
						oi.setBillId(od1.getBillId());
						int orderitem = orderitemService.insertOrderitem(oi, resultErpKind.get(i)
								.getDataSource());
						System.out.println("orderitem:" + orderitem);
					}
					System.out.println("order:" + order);
				}
		}
		if("".equals(resultMsg)){
			return ServerResponse.createBySuccessMessage("订单推送成功");
		}else{
			return ServerResponse.createBySuccessMessage(resultMsg);
			}
		}
		 }
	}
	
	
	public String checkOrder(Order order){
		String resultMsg="";
		//判断订单是否重复传输（允许下发的订单）
		Ordercheck oc=new Ordercheck();
		Map<String,Object> msg=new HashMap<String,Object>();
		Random random = new Random(); 
		msg.put("order_id", order.getBillId());
		msg.put("order_type", "允许下发");
		List<Ordercheck> succeOL=ordercheckMapper.getBillByState(msg);
		if(succeOL.size()>0){
			/*System.out.println("完成的订单重复");
			oc.setOrderId(order.getBillId()+(1000+random.nextInt(9000)));
			oc.setMsg("订单重复推送");
			oc.setOrderType("拒绝接收");
			oc.setHismsg(order.getBillId());
			int result=ordercheckMapper.insertBillCheck(oc);
			return false;*/
			throw new NotAuthedException("订单重复推送");
		}
		if(StringUtils.isBlank(order.getBillDate())||
				StringUtils.isBlank(order.getBillId())||
				StringUtils.isBlank(order.getOrgId())||
				StringUtils.isBlank(order.getOrgName())||
				order.getPayment()==null
				
				){
			throw new NotAuthedException("总单字段缺失");
		}
		
		//明细缺失，比如序号不连贯或者明细为空
		String failmsg="";
		Double payment=0.00d;
		boolean ifExist=true;
		Set<String> item=new HashSet<String>();
		List<Orderitem> oil=order.getOrderitem();
		for(int i=0;i<oil.size();i++){
			Orderitem oitemp=oil.get(i);
			boolean bl= item.add(oitemp.getItemId());
			
			if(StringUtils.isBlank(oitemp.getItemId())||
					StringUtils.isBlank(oitemp.getProductId())||
					StringUtils.isBlank(oitemp.getGeneralName())||
					StringUtils.isBlank(oitemp.getUnit())||
					oitemp.getAmount()==null||
					oitemp.getPayment()==null||
					oitemp.getPrice()==null
					){
				throw new NotAuthedException("明细单字段缺失");
			}
			
			if(ifExist==true&&bl==false){
				ifExist=bl;
			}
			if(oitemp.getPayment()==oitemp.getPrice()*oitemp.getAmount()){
				payment+=oitemp.getPayment();
			}else{
				failmsg=failmsg+"明细:"+oitemp.getItemId()+"金额、价格、数量不匹配";
			}
			
		}
		
		if(!payment.equals(order.getPayment())){
			throw new NotAuthedException("总单金额和明细金额不匹配");
		}
		if(failmsg.length()>1){
			/*msg.put("order_id", order.getBillId());
			msg.put("emorder_type", "允许下发");
			List<Ordercheck> failOL=ordercheckMapper.getBillByState(msg);
			String errorBillid="";
			if(failOL.size()>0){
				errorBillid=failOL.get(0).getOrderId()+(1000+random.nextInt(9000));
				msg.clear();
				msg.put("order_id", errorBillid);
				msg.put("id", failOL.get(0).getId());
			}
			msg.clear();
			oc.setOrderId(order.getBillId());
			oc.setMsg(failmsg);
			oc.setOrderType("拒绝接收");
			oc.setHismsg(errorBillid);
			int result=ordercheckMapper.insertBillCheck(oc);
			
			return false;*/
			throw new NotAuthedException(failmsg);
		}
		if(!(item.size()==oil.size())||ifExist==false){
			/*msg.put("order_id", order.getBillId());
			msg.put("emorder_type", "允许下发");
			List<Ordercheck> failOL=ordercheckMapper.getBillByState(msg);
			String errorBillid="";
			if(failOL.size()>0){
				errorBillid=failOL.get(0).getOrderId()+(1000+random.nextInt(9000));
				msg.clear();
				msg.put("order_id", errorBillid);
				msg.put("id", failOL.get(0).getId());
			}
			msg.clear();
			oc.setOrderId(order.getBillId());
			oc.setMsg("订单明细缺失或重复");
			oc.setOrderType("拒绝接收");
			oc.setHismsg(errorBillid);
			int result=ordercheckMapper.insertBillCheck(oc);
			return false;*/
			throw new NotAuthedException("订单明细缺失或重复");
		}
		
		//获取推送订单的商品列表
		msg.clear();
		Set<String> lsProduct=new HashSet<String>();
		Set<String> lsZt =new HashSet<String>();
		for(int i=0;i<oil.size();i++){
			Orderitem oitemp=oil.get(i);
			lsProduct.add(oitemp.getProductId());
			lsZt.add(oitemp.getProductId().substring(0, 1));
		}
		//判断该列表是否存在多个账套的商品
		msg.put("zt", lsZt);
		Set<Map<String,Object>> ztMsg=ordercheckMapper.getZtMsg(msg);
		if(!(ztMsg.size()==lsZt.size())){
			throw new NotAuthedException("多数据源维护失败错误");
		}else{
			Set<String> erpProduct=new HashSet<String>();
			erpProduct.addAll(lsProduct);
			Set<String> clientProduct=new HashSet<String>();
			clientProduct.addAll(lsProduct);
			Iterator<Map<String,Object>> iterator = ztMsg.iterator();
	        while(iterator.hasNext()){
	        	Map<String,Object> ztTemp=iterator.next();
	        	int repoint=ordercheckService.checkBaseMsg(erpProduct,clientProduct,lsProduct, order.getOrgId(),order.getClientId(),(String)ztTemp.get("account_id"),(String)ztTemp.get("data_source"));
	        	if(repoint==2){
	        		throw new NotAuthedException("客户不存在erp，拒绝接收");
	        	}else if(repoint==3){
	        		throw new NotAuthedException("客户不属于连锁客户，拒绝接收");
	        	}else if(repoint==4){
	        		resultMsg+="客户未绑定账套"+(String)ztTemp.get("account_id")+";";
//	        		throw new NotAuthedException("客户未绑定账套");
	        	}
	        }
	        if(erpProduct.size()!=0){
	        	throw new NotAuthedException("商品不完全存在erp，拒绝接收");
	        }
	        if(clientProduct.size()!=0){
	        	throw new NotAuthedException("存在商品不属于该连锁，拒绝接收");
	        }
		}
		
		
		
		return resultMsg;
	}
	
	
	
	
	

	@GetMapping("/getReviseOrder")
	@ResponseBody
	public Object getReviseOrder(@RequestParam(required = false) String orgId,
			@RequestParam(required = false) String srcBillId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		
		 String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		
		
		this.checkClient(clientId);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}

		int preCount = (num - 1) * page;

		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		Set<String> dataSource = new HashSet<String>();

		List<ReviseOrder> allOrd = new ArrayList<ReviseOrder>();
		Map<String, Object> allOrderPoint = new HashMap<String, Object>();

		for (int i = 0; i < resultErpKind.size(); i++) {
			Map<String, Object> orgMsg = new HashMap<String, Object>();
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				orgMsg.put("clientId", clientId);

				if (!StringUtils.isBlank(orgId)) {

					orgMsg.put("orgId", orgId);
				}
				//orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				int clientcus = clientcustomerService.getCount(orgMsg);
				//orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				// 先获取客户列表
				for (int j = 1; j <= clientcus / 1000 + 1; j++) {
					PageHelper.startPage(j, 1000);
					List<Clientcustomer> clientcustomer = (List<Clientcustomer>) clientcustomerService
							.selectByMsg(orgMsg);
					List<String> clientList = new ArrayList<String>();
					for (int k = 0; k < clientcustomer.size(); k++) {
						clientList.add(clientcustomer.get(k).getOrgId());
					}
					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientproductprice");
						orgMsg.put("clientList", clientList);
					}
					if (!StringUtils.isBlank(srcBillId)) {

						orgMsg.put("billId", srcBillId);
					}
					
					orgMsg.put("clientId", clientId);//clientId
					List<Order> odl = new ArrayList<Order>();
					int ordes = orderService.getCount(orgMsg);
					// 获取客户所有订单
					for (int l = 1; l <= ordes / 1000 + 1; l++) {
						PageHelper.startPage(l, 1000);
						odl = (List<Order>) orderService.selectByMsg(orgMsg);
						// int orders=orderService.getCount(orgMsg);

						Map<String, Object> orgMsg1 = new HashMap<String, Object>();
						List<String> ordList = new ArrayList<String>();
						for (int t = 0; t < odl.size(); t++) {
							ordList.add(odl.get(t).getBillId());
						}
						if (ordList.size() > 0) {
							orgMsg1.put("ordList", ordList);
						} else {
							ordList.add("clientproductprice");
							orgMsg1.put("ordList", ordList);
						}
						if (!StringUtils.isBlank(lastDate)) {
							SimpleDateFormat sdf = new SimpleDateFormat(
									"yyyy-MM-dd HH:mm:ss");

							try {
								orgMsg1.put("lastDate", sdf.parse(lastDate));
							} catch (ParseException e) {
								throw new NotAuthedException("传入日期格式错误");
							}
						}
						int allCount = iReviseOrderService.getCount(orgMsg1,
								resultErpKind.get(i).getDataSource());
						total += allCount;
						if (preCount >= allCount) {
							preCount = preCount - allCount;
							continue;
						}

						if (allOrd.size() == maxPage) {
							continue;
						}

						// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
						if ((preCount + page) >= allCount) {
							orgMsg1.put("beginNum", preCount + 1);
							orgMsg1.put("endNum", allCount);
							List<ReviseOrder> rol = (List<ReviseOrder>) iReviseOrderService
									.selectByMsg(orgMsg1, resultErpKind.get(i)
											.getDataSource());
							// 加载主表数据
							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
							List<String> orditemList = new ArrayList<String>();
							for (int r = 0; r < rol.size(); r++) {
								if (!allOrderPoint.containsKey(rol.get(r)
										.getBillId())) {
									allOrd.add(rol.get(r));
									allOrderPoint.put(
											rol.get(r).getBillId(),
											allOrd.size() - 1);
									orditemList.add(rol.get(r).getBillId());
								}
							}
							if (orditemList.size() > 0) {
								orgMsg2.put("orditemList", orditemList);
							

							Set<String> dataSource1 = new HashSet<String>();

//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
									List<ReviseOrderItem> roil = (List<ReviseOrderItem>) reviseOrderItemServiceImpl
											.selectByMsg(orgMsg2, resultErpKind
													.get(i).getDataSource());
									for (int x = 0; x < roil.size(); x++) {
										if (allOrd.size() == 100) {
											break;
										}
										ReviseOrderItemRe rr=new ReviseOrderItemRe();
										rr.setItemId(roil.get(x).getItemId());
										rr.setProductId(roil.get(x).getProductId());
										rr.setGeneralName(roil.get(x).getGeneralName());
										rr.setSpec(roil.get(x).getSpec());
										rr.setFactoryName(roil.get(x).getFactoryName());
										rr.setOrigin(roil.get(x).getOrigin());
										rr.setApprovalNo(roil.get(x).getApprovalNo());
										rr.setUnit(roil.get(x).getUnit());
										rr.setAmount(roil.get(x).getAmount());
										rr.setPrice(roil.get(x).getPrice());
										rr.setPayment(roil.get(x).getPayment());
										
										if (allOrderPoint.containsKey(roil.get(
												x).getBillId())) {

											if (allOrd
													.get((int) allOrderPoint
															.get(roil
																	.get(x)
																	.getBillId()))
													.getItems() == null) {
												List<ReviseOrderItemRe> roitemp = new ArrayList<ReviseOrderItemRe>();
												//roitemp.add(roil.get(x));
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											} else {
												List<ReviseOrderItemRe> roitemp = new ArrayList<ReviseOrderItemRe>();
												roitemp.addAll(allOrd
														.get((int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.getItems());
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											}

										}

									}
//								}
//							}

							page = preCount + page - allCount;
							preCount = 0;
							}
							/*else {
								orditemList.add("clientproductprice");
								orgMsg2.put("orditemList", orditemList);
							}*/
						} else {
							orgMsg.put("beginNum", preCount + 1);
							orgMsg.put("endNum", preCount + page);
							List<ReviseOrder> rol = (List<ReviseOrder>) iReviseOrderService
									.selectByMsg(orgMsg1, resultErpKind.get(i)
											.getDataSource());
							// 加载主表数据
							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
							List<String> orditemList = new ArrayList<String>();
							for (int r = 0; r < rol.size(); r++) {
								if (!allOrderPoint.containsKey(rol.get(r)
										.getBillId())) {
									allOrd.add(rol.get(r));
									allOrderPoint.put(
											rol.get(r).getBillId(),
											allOrd.size() - 1);
									orditemList.add(rol.get(r).getBillId());
								}
							}
							if (orditemList.size() > 0) {
								orgMsg2.put("orditemList", orditemList);
							

							Set<String> dataSource1 = new HashSet<String>();

//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
									List<ReviseOrderItem> roil = (List<ReviseOrderItem>) reviseOrderItemServiceImpl
											.selectByMsg(orgMsg2, resultErpKind
													.get(i).getDataSource());
									for (int x = 0; x < roil.size(); x++) {
										if (allOrd.size() == 100) {
											break;
										}
										ReviseOrderItemRe rr=new ReviseOrderItemRe();
										rr.setItemId(roil.get(x).getItemId());
										rr.setProductId(roil.get(x).getProductId());
										rr.setGeneralName(roil.get(x).getGeneralName());
										rr.setSpec(roil.get(x).getSpec());
										rr.setFactoryName(roil.get(x).getFactoryName());
										rr.setOrigin(roil.get(x).getOrigin());
										rr.setApprovalNo(roil.get(x).getApprovalNo());
										rr.setUnit(roil.get(x).getUnit());
										rr.setAmount(roil.get(x).getAmount());
										rr.setPrice(roil.get(x).getPrice());
										rr.setPayment(roil.get(x).getPayment());
										if (allOrderPoint.containsKey(roil.get(
												x).getBillId())) {

											if (allOrd
													.get((int) allOrderPoint
															.get(roil
																	.get(x)
																	.getBillId()))
													.getItems() == null) {
												List<ReviseOrderItemRe> roitemp = new ArrayList<ReviseOrderItemRe>();
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											} else {
												List<ReviseOrderItemRe> roitemp = new ArrayList<ReviseOrderItemRe>();
												roitemp.addAll(allOrd
														.get((int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.getItems());
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											}

										}

									}
//								}
//							}
						
							} 
							/*else {
								orditemList.add("clientproductprice");
								orgMsg2.put("orditemList", orditemList);
							}*/
							}

						// 获取修改之后的单据
						/*
						 * for (int u = 1; u <= rolCounts / 1000 + 1; u++) {
						 * 
						 * List<ReviseOrder> rol = (List<ReviseOrder>)
						 * iReviseOrderService .selectByMsg(orgMsg1,
						 * resultErpKind.get(i) .getDataSource());
						 * 
						 * // 加载主表数据 Map<String, Object> orgMsg2 = new
						 * HashMap<String, Object>(); List<String> orditemList =
						 * new ArrayList<String>(); for (int x = rolCounts -
						 * preCount - 1; x <= rol .size() - 1; x++) { if
						 * (allOrd.size() == 100) { break; } if
						 * (!allOrderPoint.containsKey(rol.get(x)
						 * .getSrcBillId())) { allOrd.add(rol.get(x));
						 * allOrderPoint.put( rol.get(x).getSrcBillId(),
						 * allOrd.size() - 1);
						 * orditemList.add(rol.get(x).getSrcBillId()); }
						 * 
						 * }
						 * 
						 * if (orditemList.size() > 0) {
						 * orgMsg2.put("orditemList", orditemList); } else {
						 * orditemList.add("clientproductprice");
						 * orgMsg2.put("orditemList", orditemList); }
						 * 
						 * Set<String> dataSource1 = new HashSet<String>();
						 * 
						 * for (int p = 0; p < resultErpKind.size(); p++) { if
						 * (dataSource1.add(resultErpKind.get(p)
						 * .getDataSource())) { List<ReviseOrderItem> roil =
						 * (List<ReviseOrderItem>) reviseOrderItemServiceImpl
						 * .selectByMsg(orgMsg2, resultErpKind
						 * .get(p).getDataSource()); for (int x = 0; x <
						 * roil.size(); x++) { if (allOrd.size() == 100) {
						 * break; } if (allOrderPoint.containsKey(roil.get(
						 * x).getSrcBillId())) {
						 * 
						 * if (allOrd .get((int) allOrderPoint .get(roil .get(x)
						 * .getSrcBillId())) .getItems() == null) {
						 * List<ReviseOrderItem> roitemp = new
						 * ArrayList<ReviseOrderItem>();
						 * roitemp.add(roil.get(x)); allOrd.get( (int)
						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
						 * .setItems(roitemp); } else { List<ReviseOrderItem>
						 * roitemp = new ArrayList<ReviseOrderItem>();
						 * roitemp.addAll(allOrd .get((int) allOrderPoint
						 * .get(roil .get(x) .getSrcBillId())) .getItems());
						 * roitemp.add(roil.get(x)); allOrd.get( (int)
						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
						 * .setItems(roitemp); }
						 * 
						 * }
						 * 
						 * } } }
						 * 
						 * }
						 */

					}

				}
				orgMsg.clear();
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(total / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrd);

		System.out.println(allOrd.toString());
		return ServerResponse.createBySuccess("获取修改单成功", rd);
		 }
	}
	
	
	
	@GetMapping("/getOutOrder")
	@ResponseBody
	public Object getOutOrder(@RequestParam(required = false) String orgId,
			@RequestParam(required = false) String srcBillId,
			@RequestParam(required = false) String pageNum,
			@RequestParam(required = false) String lastDate,
			HttpServletRequest request) {
		/*
		 * String transToken = request.getHeader("Authorization"); String
		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
		 * return //
		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
		 * new AuthenticationException("未登录"); } else {
		 */
		
		 String transToken = request.getHeader("Authorization"); 
		  String clientId = request.getHeader("client_id"); 
		  // 判断token是否合法
		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
			  //return 
			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
			  throw new AuthenticationException("未登录"); 
			} else {
		
		
		this.checkClient(clientId);
		int num = 1;
		int page = 100;
		int maxPage = page;
		int total = 0;
		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
			num = Integer.parseInt(pageNum);
		}

		int preCount = (num - 1) * page;

		List<Erpkind> resultErpKind = erpkindService.selectList(null);
		Set<String> dataSource = new HashSet<String>();

		List<OutOrder> allOrd = new ArrayList<OutOrder>();
		Map<String, Object> allOrderPoint = new HashMap<String, Object>();

		for (int i = 0; i < resultErpKind.size(); i++) {
			Map<String, Object> orgMsg = new HashMap<String, Object>();
			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
				orgMsg.put("clientId", clientId);

				if (!StringUtils.isBlank(orgId)) {

					orgMsg.put("orgId", orgId);
				}
				//orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				int clientcus = clientcustomerService.getCount(orgMsg);
				//orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
				// 先获取客户列表
				for (int j = 1; j <= clientcus / 1000 + 1; j++) {
					PageHelper.startPage(j, 1000);
					List<Clientcustomer> clientcustomer = (List<Clientcustomer>) clientcustomerService
							.selectByMsg(orgMsg);
					List<String> clientList = new ArrayList<String>();
					for (int k = 0; k < clientcustomer.size(); k++) {
						clientList.add(clientcustomer.get(k).getOrgId());
					}
					if (clientList.size() > 0) {
						orgMsg.put("clientList", clientList);
					} else {
						clientList.add("clientproductprice");
						orgMsg.put("clientList", clientList);
					}
					orgMsg.put("clientId", clientId);//clientId
					
					if (!StringUtils.isBlank(srcBillId)) {

						orgMsg.put("billId", srcBillId);
					}
					
					
					List<Order> odl = new ArrayList<Order>();
					int ordes = orderService.getCount(orgMsg);
					// 获取客户所有订单
					for (int l = 1; l <= ordes / 1000 + 1; l++) {
						PageHelper.startPage(l, 1000);
						odl = (List<Order>) orderService.selectByMsg(orgMsg);
						// int orders=orderService.getCount(orgMsg);

						Map<String, Object> orgMsg1 = new HashMap<String, Object>();
						List<String> ordList = new ArrayList<String>();
						for (int t = 0; t < odl.size(); t++) {
							ordList.add(odl.get(t).getBillId());
						}
						if (ordList.size() > 0) {
							orgMsg1.put("ordList", ordList);
						} else {
							ordList.add("clientproductprice");
							orgMsg1.put("ordList", ordList);
						}
						if (!StringUtils.isBlank(lastDate)) {
							SimpleDateFormat sdf = new SimpleDateFormat(
									"yyyy-MM-dd HH:mm:ss");

							try {
								orgMsg1.put("lastDate", sdf.parse(lastDate));
							} catch (ParseException e) {
								throw new NotAuthedException("传入日期格式错误");
							}
						}
						int allCount = outOrderService.getCount(orgMsg1,
								resultErpKind.get(i).getDataSource());
						total += allCount;
						if (preCount >= allCount) {
							preCount = preCount - allCount;
							continue;
						}

						if (allOrd.size() == maxPage) {
							continue;
						}

						// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
						if ((preCount + page) >= allCount) {
							orgMsg1.put("beginNum", preCount + 1);
							orgMsg1.put("endNum", allCount);
							List<OutOrder> rol = (List<OutOrder>) outOrderService
									.selectByMsg(orgMsg1, resultErpKind.get(i)
											.getDataSource());
							// 加载主表数据
							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
							List<String> orditemList = new ArrayList<String>();
							for (int r = 0; r < rol.size(); r++) {
								if (!allOrderPoint.containsKey(rol.get(r)
										.getBillId())) {
									allOrd.add(rol.get(r));
									allOrderPoint.put(
											rol.get(r).getBillId(),
											allOrd.size() - 1);
									orditemList.add(rol.get(r).getBillId());
								}
							}
							if (orditemList.size() > 0) {
								orgMsg2.put("orditemList", orditemList);
							

							Set<String> dataSource1 = new HashSet<String>();

//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
									List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
											.selectByMsg(orgMsg2, resultErpKind
													.get(i).getDataSource());
									for (int x = 0; x < roil.size(); x++) {
										if (allOrd.size() == 100) {
											break;
										}
										
										OutOrderItemRe rr=new OutOrderItemRe();
										rr.setItemId(roil.get(x).getItemId());
										rr.setProductId(roil.get(x).getProductId());
										rr.setGeneralName(roil.get(x).getGeneralName());
										rr.setSpec(roil.get(x).getSpec());
										rr.setFactoryName(roil.get(x).getFactoryName());
										rr.setOrigin(roil.get(x).getOrigin());
										rr.setApprovalNo(roil.get(x).getApprovalNo());
										rr.setUnit(roil.get(x).getUnit());
										rr.setProduceDate(roil.get(x).getProduceDate());
										rr.setExpiryDate(roil.get(x).getExpiryDate());
										rr.setBatchNo(roil.get(x).getBatchNo());
										rr.setAmount(roil.get(x).getAmount());
										rr.setPrice(roil.get(x).getPrice());
										rr.setPayment(roil.get(x).getPayment());
										
										
										if (allOrderPoint.containsKey(roil.get(
												x).getBillId())) {

											if (allOrd
													.get((int) allOrderPoint
															.get(roil
																	.get(x)
																	.getBillId()))
													.getItems() == null) {
												List<OutOrderItemRe> roitemp = new ArrayList<OutOrderItemRe>();
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											} else {
												List<OutOrderItemRe> roitemp = new ArrayList<OutOrderItemRe>();
												roitemp.addAll(allOrd
														.get((int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.getItems());
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											}

										}

									}
//								}
//							}

							page = preCount + page - allCount;
							preCount = 0;
							}
							/*else {
								orditemList.add("clientproductprice");
								orgMsg2.put("orditemList", orditemList);
							}*/
						} else {
							orgMsg.put("beginNum", preCount + 1);
							orgMsg.put("endNum", preCount + page);
							List<OutOrder> rol = (List<OutOrder>) outOrderService
									.selectByMsg(orgMsg1, resultErpKind.get(i)
											.getDataSource());
							// 加载主表数据
							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
							List<String> orditemList = new ArrayList<String>();
							for (int r = 0; r < rol.size(); r++) {
								if (!allOrderPoint.containsKey(rol.get(r)
										.getBillId())) {
									allOrd.add(rol.get(r));
									allOrderPoint.put(
											rol.get(r).getBillId(),
											allOrd.size() - 1);
									orditemList.add(rol.get(r).getBillId());
								}
							}
							if (orditemList.size() > 0) {
								orgMsg2.put("orditemList", orditemList);
							

							Set<String> dataSource1 = new HashSet<String>();

//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
									List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
											.selectByMsg(orgMsg2, resultErpKind
													.get(i).getDataSource());
									for (int x = 0; x < roil.size(); x++) {
										if (allOrd.size() == 100) {
											break;
										}
										
										OutOrderItemRe rr=new OutOrderItemRe();
										rr.setItemId(roil.get(x).getItemId());
										rr.setProductId(roil.get(x).getProductId());
										rr.setGeneralName(roil.get(x).getGeneralName());
										rr.setSpec(roil.get(x).getSpec());
										rr.setFactoryName(roil.get(x).getFactoryName());
										rr.setOrigin(roil.get(x).getOrigin());
										rr.setApprovalNo(roil.get(x).getApprovalNo());
										rr.setUnit(roil.get(x).getUnit());
										rr.setProduceDate(roil.get(x).getProduceDate());
										rr.setExpiryDate(roil.get(x).getExpiryDate());
										rr.setBatchNo(roil.get(x).getBatchNo());
										rr.setAmount(roil.get(x).getAmount());
										rr.setPrice(roil.get(x).getPrice());
										rr.setPayment(roil.get(x).getPayment());
										
										if (allOrderPoint.containsKey(roil.get(
												x).getBillId())) {

											if (allOrd
													.get((int) allOrderPoint
															.get(roil
																	.get(x)
																	.getBillId()))
													.getItems() == null) {
												List<OutOrderItemRe> roitemp = new ArrayList<OutOrderItemRe>();
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											} else {
												List<OutOrderItemRe> roitemp = new ArrayList<OutOrderItemRe>();
												roitemp.addAll(allOrd
														.get((int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.getItems());
												roitemp.add(rr);
												allOrd.get(
														(int) allOrderPoint
																.get(roil
																		.get(x)
																		.getBillId()))
														.setItems(roitemp);
											}

										}

									}
//								}
//							}
						
							} 
							/*else {
								orditemList.add("clientproductprice");
								orgMsg2.put("orditemList", orditemList);
							}*/
							}

						// 获取修改之后的单据
						/*
						 * for (int u = 1; u <= rolCounts / 1000 + 1; u++) {
						 * 
						 * List<ReviseOrder> rol = (List<ReviseOrder>)
						 * iReviseOrderService .selectByMsg(orgMsg1,
						 * resultErpKind.get(i) .getDataSource());
						 * 
						 * // 加载主表数据 Map<String, Object> orgMsg2 = new
						 * HashMap<String, Object>(); List<String> orditemList =
						 * new ArrayList<String>(); for (int x = rolCounts -
						 * preCount - 1; x <= rol .size() - 1; x++) { if
						 * (allOrd.size() == 100) { break; } if
						 * (!allOrderPoint.containsKey(rol.get(x)
						 * .getSrcBillId())) { allOrd.add(rol.get(x));
						 * allOrderPoint.put( rol.get(x).getSrcBillId(),
						 * allOrd.size() - 1);
						 * orditemList.add(rol.get(x).getSrcBillId()); }
						 * 
						 * }
						 * 
						 * if (orditemList.size() > 0) {
						 * orgMsg2.put("orditemList", orditemList); } else {
						 * orditemList.add("clientproductprice");
						 * orgMsg2.put("orditemList", orditemList); }
						 * 
						 * Set<String> dataSource1 = new HashSet<String>();
						 * 
						 * for (int p = 0; p < resultErpKind.size(); p++) { if
						 * (dataSource1.add(resultErpKind.get(p)
						 * .getDataSource())) { List<ReviseOrderItem> roil =
						 * (List<ReviseOrderItem>) reviseOrderItemServiceImpl
						 * .selectByMsg(orgMsg2, resultErpKind
						 * .get(p).getDataSource()); for (int x = 0; x <
						 * roil.size(); x++) { if (allOrd.size() == 100) {
						 * break; } if (allOrderPoint.containsKey(roil.get(
						 * x).getSrcBillId())) {
						 * 
						 * if (allOrd .get((int) allOrderPoint .get(roil .get(x)
						 * .getSrcBillId())) .getItems() == null) {
						 * List<ReviseOrderItem> roitemp = new
						 * ArrayList<ReviseOrderItem>();
						 * roitemp.add(roil.get(x)); allOrd.get( (int)
						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
						 * .setItems(roitemp); } else { List<ReviseOrderItem>
						 * roitemp = new ArrayList<ReviseOrderItem>();
						 * roitemp.addAll(allOrd .get((int) allOrderPoint
						 * .get(roil .get(x) .getSrcBillId())) .getItems());
						 * roitemp.add(roil.get(x)); allOrd.get( (int)
						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
						 * .setItems(roitemp); }
						 * 
						 * }
						 * 
						 * } } }
						 * 
						 * }
						 */

					}

				}
				orgMsg.clear();
			}
		}
		ResponseData rd = new ResponseData();
		/*
		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
		 * rd.setTotal(total / 100); }
		 */
		rd.setPageNum(num);
		rd.setPageSize(maxPage);
		rd.setTotal(total);
		rd.setRows((ArrayList) allOrd);

		System.out.println(allOrd.toString());
		return ServerResponse.createBySuccess("获取出库单成功", rd);
		}
	}	

//	@GetMapping("/getOutOrder")
//	@ResponseBody
//	public Object getOutOrder(@RequestParam(required = false) String orgId,
//			@RequestParam(required = false) String pageNum,
//			@RequestParam(required = false) String lastDate,
//			HttpServletRequest request) {
//		/*
//		 * String transToken = request.getHeader("Authorization"); String
//		 * clientId = request.getHeader("client_id"); // 判断token是否合法 if
//		 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { //
//		 * return //
//		 * ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
//		 * new AuthenticationException("未登录"); } else {
//		 */
//		 String transToken = request.getHeader("Authorization"); 
//		  String clientId = request.getHeader("client_id"); 
//		  // 判断token是否合法
//		  if(StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { 
//			  //return 
//			  //ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); 
//			  throw new AuthenticationException("未登录"); 
//			} else {
////		
//		
//
//		int num = 1;
//		int page = 100;
//		int maxPage = page;
//		int total = 0;
//		if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) {
//			num = Integer.parseInt(pageNum);
//		}
//
//		int preCount = (num - 1) * page;
//
//		List<Erpkind> resultErpKind = erpkindService.selectList(null);
//		Set<String> dataSource = new HashSet<String>();
//
//		List<OutOrder> allOrd = new ArrayList<OutOrder>();
//		Map<String, Object> allOrderPoint = new HashMap<String, Object>();
//
//		for (int i = 0; i < resultErpKind.size(); i++) {
//			Map<String, Object> orgMsg = new HashMap<String, Object>();
//			if (dataSource.add(resultErpKind.get(i).getDataSource())) {
//				orgMsg.put("clientId", clientId);
//
//				if (!StringUtils.isBlank(orgId)) {
//
//					orgMsg.put("orgId", orgId);
//				}
////				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
//				int clientcus = clientcustomerService.getCount(orgMsg);
////				orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
//				// 先获取客户列表
//				for (int j = 1; j <= clientcus / 1000 + 1; j++) {
//					PageHelper.startPage(j, 1000);
//					List<Clientcustomer> clientcustomer = (List<Clientcustomer>) clientcustomerService
//							.selectByMsg(orgMsg);
//					List<String> clientList = new ArrayList<String>();
//					for (int k = 0; k < clientcustomer.size(); k++) {
//						clientList.add(clientcustomer.get(k).getOrgId());
//					}
//					if (clientList.size() > 0) {
//						orgMsg.put("clientList", clientList);
//					} else {
//						clientList.add("clientproductprice");
//						orgMsg.put("clientList", clientList);
//					}
//					orgMsg.put("clientId", clientId);//clientId
//					List<Order> odl = new ArrayList<Order>();
//					int ordes = orderService.getCount(orgMsg);
//					// 获取客户所有订单
//					for (int l = 1; l <= ordes / 1000 + 1; l++) {
//						PageHelper.startPage(l, 1000);
//						odl = (List<Order>) orderService.selectByMsg(orgMsg);
//						// int orders=orderService.getCount(orgMsg);
//
//						Map<String, Object> orgMsg1 = new HashMap<String, Object>();
//						List<String> ordList = new ArrayList<String>();
//						for (int t = 0; t < odl.size(); t++) {
//							ordList.add(odl.get(t).getBillId());
//						}
//						if (ordList.size() > 0) {
//							orgMsg1.put("ordList", ordList);
//						} else {
//							ordList.add("clientproductprice");
//							orgMsg1.put("ordList", ordList);
//						}
//						if (!StringUtils.isBlank(lastDate)) {
//							SimpleDateFormat sdf = new SimpleDateFormat(
//									"yyyy-MM-dd HH:mm:ss");
//
//							try {
//								orgMsg1.put("lastDate", sdf.parse(lastDate));
//							} catch (ParseException e) {
//								throw new NotAuthedException("传入日期格式错误");
//							}
//						}
//						int allCount = iReviseOrderService.getCount(orgMsg1,
//								resultErpKind.get(i).getDataSource());
//						total += allCount;
//						if (preCount >= allCount) {
//							preCount = preCount - allCount;
//							continue;
//						}
//
//						if (allOrd.size() == maxPage) {
//							continue;
//						}
//
//						// 如果当前数据库查出来的条目数比当前页码的前置数据大则在当前页获取数据
//						if ((preCount + page) >= allCount) {
//							orgMsg1.put("beginNum", preCount + 1);
//							orgMsg1.put("endNum", allCount);
//							List<OutOrder> rol = (List<OutOrder>) outOrderService
//									.selectByMsg(orgMsg1, resultErpKind.get(i)
//											.getDataSource());
//							// 加载主表数据
//							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
//							List<String> orditemList = new ArrayList<String>();
//							for (int r = 0; r < rol.size(); r++) {
//								if (!allOrderPoint.containsKey(rol.get(r)
//										.getBillId())) {
//									allOrd.add(rol.get(r));
//									allOrderPoint.put(
//											rol.get(r).getBillId(),
//											allOrd.size() - 1);
//									orditemList.add(rol.get(r).getBillId());
//								}
//							}
//							if (orditemList.size() > 0) {
//								orgMsg2.put("orditemList", orditemList);
//							
//
//							Set<String> dataSource1 = new HashSet<String>();
//
//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
//									List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
//											.selectByMsg(orgMsg2, resultErpKind
//													.get(p).getDataSource());
//									for (int x = 0; x < roil.size(); x++) {
//										if (allOrd.size() == 100) {
//											break;
//										}
//										if (allOrderPoint.containsKey(roil.get(
//												x).getBillId())) {
//
//											if (allOrd
//													.get((int) allOrderPoint
//															.get(roil
//																	.get(x)
//																	.getBillId()))
//													.getItems() == null) {
//												List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
//												roitemp.add(roil.get(x));
//												allOrd.get(
//														(int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.setItems(roitemp);
//											} else {
//												List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
//												roitemp.addAll(allOrd
//														.get((int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.getItems());
//												roitemp.add(roil.get(x));
//												allOrd.get(
//														(int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.setItems(roitemp);
//											}
//
//										}
//
//									}
//								}
//							}
//
//							page = preCount + page - allCount;
//							preCount = 0;
//							} 
//							/*else {
//								orditemList.add("clientproductprice");
//								orgMsg2.put("orditemList", orditemList);
//							}*/
//						} else {
//							orgMsg.put("beginNum", preCount + 1);
//							orgMsg.put("endNum", preCount + page);
//							List<OutOrder> rol = (List<OutOrder>) outOrderService
//									.selectByMsg(orgMsg1, resultErpKind.get(i)
//											.getDataSource());
//							// 加载主表数据
//							Map<String, Object> orgMsg2 = new HashMap<String, Object>();
//							List<String> orditemList = new ArrayList<String>();
//							for (int r = 0; r < rol.size(); r++) {
//								if (!allOrderPoint.containsKey(rol.get(r)
//										.getBillId())) {
//									allOrd.add(rol.get(r));
//									allOrderPoint.put(
//											rol.get(r).getBillId(),
//											allOrd.size() - 1);
//									orditemList.add(rol.get(r).getBillId());
//								}
//							}
//							if (orditemList.size() > 0) {
//								orgMsg2.put("orditemList", orditemList);
//							
//
//							Set<String> dataSource1 = new HashSet<String>();
//
//							for (int p = 0; p < resultErpKind.size(); p++) {
//								if (dataSource1.add(resultErpKind.get(p)
//										.getDataSource())) {
//									List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
//											.selectByMsg(orgMsg2, resultErpKind
//													.get(p).getDataSource());
//									for (int x = 0; x < roil.size(); x++) {
//										if (allOrd.size() == 100) {
//											break;
//										}
//										if (allOrderPoint.containsKey(roil.get(
//												x).getBillId())) {
//
//											if (allOrd
//													.get((int) allOrderPoint
//															.get(roil
//																	.get(x)
//																	.getBillId()))
//													.getItems() == null) {
//												List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
//												roitemp.add(roil.get(x));
//												allOrd.get(
//														(int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.setItems(roitemp);
//											} else {
//												List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
//												roitemp.addAll(allOrd
//														.get((int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.getItems());
//												roitemp.add(roil.get(x));
//												allOrd.get(
//														(int) allOrderPoint
//																.get(roil
//																		.get(x)
//																		.getBillId()))
//														.setItems(roitemp);
//											}
//
//										}
//
//									}
//								}
//							}
//						
//							} 
//							/*else {
//								orditemList.add("clientproductprice");
//								orgMsg2.put("orditemList", orditemList);
//							}*/	
//						}
//
//						// 获取修改之后的单据
//						/*
//						 * for (int u = 1; u <= rolCounts / 1000 + 1; u++) {
//						 * 
//						 * List<ReviseOrder> rol = (List<ReviseOrder>)
//						 * iReviseOrderService .selectByMsg(orgMsg1,
//						 * resultErpKind.get(i) .getDataSource());
//						 * 
//						 * // 加载主表数据 Map<String, Object> orgMsg2 = new
//						 * HashMap<String, Object>(); List<String> orditemList =
//						 * new ArrayList<String>(); for (int x = rolCounts -
//						 * preCount - 1; x <= rol .size() - 1; x++) { if
//						 * (allOrd.size() == 100) { break; } if
//						 * (!allOrderPoint.containsKey(rol.get(x)
//						 * .getSrcBillId())) { allOrd.add(rol.get(x));
//						 * allOrderPoint.put( rol.get(x).getSrcBillId(),
//						 * allOrd.size() - 1);
//						 * orditemList.add(rol.get(x).getSrcBillId()); }
//						 * 
//						 * }
//						 * 
//						 * if (orditemList.size() > 0) {
//						 * orgMsg2.put("orditemList", orditemList); } else {
//						 * orditemList.add("clientproductprice");
//						 * orgMsg2.put("orditemList", orditemList); }
//						 * 
//						 * Set<String> dataSource1 = new HashSet<String>();
//						 * 
//						 * for (int p = 0; p < resultErpKind.size(); p++) { if
//						 * (dataSource1.add(resultErpKind.get(p)
//						 * .getDataSource())) { List<ReviseOrderItem> roil =
//						 * (List<ReviseOrderItem>) reviseOrderItemServiceImpl
//						 * .selectByMsg(orgMsg2, resultErpKind
//						 * .get(p).getDataSource()); for (int x = 0; x <
//						 * roil.size(); x++) { if (allOrd.size() == 100) {
//						 * break; } if (allOrderPoint.containsKey(roil.get(
//						 * x).getSrcBillId())) {
//						 * 
//						 * if (allOrd .get((int) allOrderPoint .get(roil .get(x)
//						 * .getSrcBillId())) .getItems() == null) {
//						 * List<ReviseOrderItem> roitemp = new
//						 * ArrayList<ReviseOrderItem>();
//						 * roitemp.add(roil.get(x)); allOrd.get( (int)
//						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
//						 * .setItems(roitemp); } else { List<ReviseOrderItem>
//						 * roitemp = new ArrayList<ReviseOrderItem>();
//						 * roitemp.addAll(allOrd .get((int) allOrderPoint
//						 * .get(roil .get(x) .getSrcBillId())) .getItems());
//						 * roitemp.add(roil.get(x)); allOrd.get( (int)
//						 * allOrderPoint .get(roil .get(x) .getSrcBillId()))
//						 * .setItems(roitemp); }
//						 * 
//						 * }
//						 * 
//						 * } } }
//						 * 
//						 * }
//						 */
//
//					}
//
//				}
//				orgMsg.clear();
//			}
//		}
//		ResponseData rd = new ResponseData();
//		/*
//		 * if (total % 100 > 0) { rd.setTotal((total / 100) + 1); } else {
//		 * rd.setTotal(total / 100); }
//		 */
//		rd.setPageNum(num);
//		rd.setPageSize(maxPage);
//		rd.setTotal(total);
//		rd.setRows((ArrayList) allOrd);
//
//		System.out.println(allOrd.toString());
//		return ServerResponse.createBySuccess("获取出库单成功", rd);
//		 }
//	}

	/*
	 * @GetMapping("/getOutOrder")
	 * 
	 * @ResponseBody public Object getOutOrder(@RequestParam(required = false)
	 * String orgId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else {
	 * 
	 * 
	 * int num = 1; int page = 100; int total = 0; if
	 * (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num =
	 * Integer.parseInt(pageNum); }
	 * 
	 * int preCount = (num - 1) * page;
	 * 
	 * List<Erpkind> resultErpKind = erpkindService.selectList(null);
	 * Set<String> dataSource = new HashSet<String>();
	 * 
	 * List<OutOrder> allOrd = new ArrayList<OutOrder>(); Map<String, Object>
	 * allOrderPoint = new HashMap<String, Object>(); int allCount = 0;
	 * 
	 * for (int i = 0; i < resultErpKind.size(); i++) { Map<String, Object>
	 * orgMsg = new HashMap<String, Object>(); if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * orgMsg.put("clientId", "guorenclient");
	 * 
	 * if (!StringUtils.isBlank(orgId)) {
	 * 
	 * orgMsg.put("orgId", orgId); } orgMsg.put("dataType",
	 * resultErpKind.get(i).getAccountId()); int clientcus =
	 * clientcustomerService.getCount(orgMsg); orgMsg.put("dataType",
	 * resultErpKind.get(i).getAccountId()); // 先获取客户列表 for (int j = 1; j <=
	 * clientcus / 1000 + 1; j++) { PageHelper.startPage(j, 1000);
	 * List<Clientcustomer> clientcustomer = (List<Clientcustomer>)
	 * clientcustomerService .selectByMsg(orgMsg); List<String> clientList = new
	 * ArrayList<String>(); for (int k = 0; k < clientcustomer.size(); k++) {
	 * clientList.add(clientcustomer.get(k).getOrgId()); } if (clientList.size()
	 * > 0) { orgMsg.put("clientList", clientList); } else {
	 * clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); }
	 * 
	 * List<Order> odl = new ArrayList<Order>(); int ordes =
	 * orderService.getCount(orgMsg); // 获取客户所有订单 for (int l = 1; l <= ordes /
	 * 1000 + 1; l++) { PageHelper.startPage(l, 1000); odl = (List<Order>)
	 * orderService.selectByMsg(orgMsg); // int
	 * orders=orderService.getCount(orgMsg);
	 * 
	 * Map<String, Object> orgMsg1 = new HashMap<String, Object>(); List<String>
	 * ordList = new ArrayList<String>(); for (int t = 0; t < odl.size(); t++) {
	 * ordList.add(odl.get(t).getBillId()); } if (ordList.size() > 0) {
	 * orgMsg1.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg1.put("ordList", ordList); } if
	 * (!StringUtils.isBlank(lastDate)) { SimpleDateFormat sdf = new
	 * SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg1.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * int rolCounts = outOrderService.getCount(orgMsg1,
	 * resultErpKind.get(i).getDataSource()); total += rolCounts; if (preCount
	 * >= rolCounts) { preCount = preCount - rolCounts; break; } // 获取修改之后的单据
	 * for (int u = 1; u <= rolCounts / 1000 + 1; u++) {
	 * 
	 * List<OutOrder> rol = (List<OutOrder>) outOrderService
	 * .selectByMsg(orgMsg1, resultErpKind.get(i) .getDataSource());
	 * 
	 * // 加载主表数据 Map<String, Object> orgMsg2 = new HashMap<String, Object>();
	 * List<String> orditemList = new ArrayList<String>(); for (int x =
	 * rolCounts - preCount - 1; x <= rol .size() - 1; x++) { if (allOrd.size()
	 * == 100) { break; } if (!allOrderPoint.containsKey(rol.get(x)
	 * .getSrcBillId())) { allOrd.add(rol.get(x)); allOrderPoint.put(
	 * rol.get(x).getSrcBillId(), allOrd.size() - 1);
	 * orditemList.add(rol.get(x).getSrcBillId()); }
	 * 
	 * }
	 * 
	 * if (orditemList.size() > 0) { orgMsg2.put("orditemList", orditemList); }
	 * else { orditemList.add("clientproductprice"); orgMsg2.put("orditemList",
	 * orditemList); }
	 * 
	 * Set<String> dataSource1 = new HashSet<String>();
	 * 
	 * for (int p = 0; p < resultErpKind.size(); p++) { if
	 * (dataSource1.add(resultErpKind.get(p) .getDataSource())) {
	 * List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
	 * .selectByMsg(orgMsg2, resultErpKind .get(p).getDataSource()); for (int x
	 * = 0; x < roil.size(); x++) { if (allOrd.size() == 100) { break; } if
	 * (allOrderPoint.containsKey(roil.get( x).getSrcBillId())) {
	 * 
	 * if (allOrd .get((int) allOrderPoint .get(roil .get(x) .getSrcBillId()))
	 * .getItems() == null) { List<OutOrderItem> roitemp = new
	 * ArrayList<OutOrderItem>(); roitemp.add(roil.get(x)); allOrd.get( (int)
	 * allOrderPoint .get(roil .get(x) .getSrcBillId())) .setItems(roitemp); }
	 * else { List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
	 * roitemp.addAll(allOrd .get((int) allOrderPoint .get(roil .get(x)
	 * .getSrcBillId())) .getItems()); roitemp.add(roil.get(x)); allOrd.get(
	 * (int) allOrderPoint .get(roil .get(x) .getSrcBillId()))
	 * .setItems(roitemp); }
	 * 
	 * }
	 * 
	 * } } }
	 * 
	 * }
	 * 
	 * }
	 * 
	 * } orgMsg.clear(); } } ResponseData rd = new ResponseData(); if (total %
	 * 100 > 0) { rd.setTotal((total / 100) + 1); } else { rd.setTotal(total /
	 * 100); } rd.setRows((ArrayList) allOrd);
	 * 
	 * System.out.println(allOrd.toString()); return
	 * ServerResponse.createBySuccess("获取修改单成功", rd); // } }
	 */

	/*
	 * @GetMapping("/getOutOrder")
	 * 
	 * @ResponseBody public Object getOutOrder(@RequestParam(required = false)
	 * String orgId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else {
	 * 
	 * 
	 * int num = 1; int page = 100; int total = 0; if
	 * (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num =
	 * Integer.parseInt(pageNum); } Map<String, Object> orgMsg = new
	 * HashMap<String, Object>(); if (!StringUtils.isBlank(lastDate)) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * 
	 * List<Erpkind> resultErpKind = erpkindService.selectList(null);
	 * Set<String> dataSource = new HashSet<String>(); List<String> clientList =
	 * new ArrayList<String>(); for (int i = 0; i < resultErpKind.size(); i++) {
	 * if (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * orgMsg.put("clientId", "guorenclient");
	 * 
	 * if (!StringUtils.isBlank(orgId)) {
	 * 
	 * orgMsg.put("orgId", orgId); } orgMsg.put("dataType",
	 * resultErpKind.get(i).getAccountId()); int clientcus =
	 * clientcustomerService.getCount(orgMsg); for (int j = 1; j <= clientcus /
	 * 1000 + 1; j++) { PageHelper.startPage(j, 1000); List<Clientcustomer>
	 * clientcustomer = (List<Clientcustomer>) clientcustomerService
	 * .selectByMsg(orgMsg); for (int k = 0; k < clientcustomer.size(); k++) {
	 * clientList.add(clientcustomer.get(k).getOrgId()); } } orgMsg.clear(); } }
	 * dataSource.clear(); orgMsg.clear(); List<OutOrder> allOrd = new
	 * ArrayList<OutOrder>(); Map<String, Object> allOrderPoint = new
	 * HashMap<String, Object>(); int allCount = 0; List<Order> odl = new
	 * ArrayList<Order>();
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); }
	 * 
	 * if (odl.size() == 0) { allCount = orderService.getCount(orgMsg); total +=
	 * allCount; // if(allCount>100*(num-1) &&page>0){ for (int y = num; y <=
	 * total / 100 + 1; y++) {
	 * 
	 * PageHelper.startPage(num, page); odl = (List<Order>)
	 * orderService.selectByMsg(orgMsg);
	 * 
	 * Map<String, Object> orgMsg1 = new HashMap<String, Object>(); List<String>
	 * ordList = new ArrayList<String>(); for (int j = 0; j < odl.size(); j++) {
	 * ordList.add(odl.get(j).getBillId()); } if (ordList.size() > 0) {
	 * orgMsg1.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg1.put("ordList", ordList); } for
	 * (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * 
	 * List<OutOrder> rol = (List<OutOrder>) outOrderService
	 * .selectByMsg(orgMsg1, resultErpKind.get(i) .getDataSource());
	 * List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
	 * .selectByMsg(orgMsg1, resultErpKind.get(i) .getDataSource()); // 加载主表数据
	 * for (int x = 0; x < rol.size(); x++) { if
	 * (!allOrderPoint.containsKey(rol.get(x) .getSrcBillId())) {
	 * allOrd.add(rol.get(x)); allOrderPoint.put(rol.get(x).getSrcBillId(),
	 * allOrd.size() - 1); } if (allOrd.size() == 100) { break; } } for (int x =
	 * 0; x < roil.size(); x++) { if (allOrderPoint.containsKey(roil.get(x)
	 * .getSrcBillId())) {
	 * 
	 * if (allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).getItems() == null) { List<OutOrderItem> roitemp = new
	 * ArrayList<OutOrderItem>(); roitemp.add(roil.get(x)); allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).setItems( roitemp); }
	 * else { List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
	 * roitemp.addAll(allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())) .getItems()); roitemp.add(roil.get(x)); allOrd.get(
	 * (int) allOrderPoint.get(roil.get(x) .getSrcBillId())).setItems( roitemp);
	 * }
	 * 
	 * }
	 * 
	 * }
	 * 
	 * // page = page - allOrd.size();
	 * 
	 * }
	 * 
	 * } if (allOrd.size() == 100) { break; } // num = 1;
	 * 
	 * }
	 * 
	 * }else{ num=num-allCount/100; }
	 * 
	 * } ResponseData rd = new ResponseData(); if (total % 100 > 0) {
	 * rd.setTotal((total / 100) + 1); } else { rd.setTotal(total / 100); }
	 * rd.setRows((ArrayList) allOrd);
	 * 
	 * System.out.println(allOrd.toString()); return
	 * ServerResponse.createBySuccess("获取出库单成功", rd); // } }
	 */

	/*
	 * @GetMapping("/getOutOrder")
	 * 
	 * @ResponseBody public Object getOutOrder(@RequestParam(required = false)
	 * String orgId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else {
	 * 
	 * 
	 * int num = 1; int page = 100; int total = 0; if
	 * (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num =
	 * Integer.parseInt(pageNum); } Map<String, Object> orgMsg = new
	 * HashMap<String, Object>(); if (!StringUtils.isBlank(lastDate)) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * 
	 * List<Erpkind> resultErpKind = erpkindService.selectList(null);
	 * Set<String> dataSource = new HashSet<String>(); List<String> clientList =
	 * new ArrayList<String>(); for (int i = 0; i < resultErpKind.size(); i++) {
	 * if (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * orgMsg.put("clientId", "guorenclient");
	 * 
	 * if (!StringUtils.isBlank(orgId)) {
	 * 
	 * orgMsg.put("orgId", orgId); } orgMsg.put("dataType",
	 * resultErpKind.get(i).getAccountId()); int clientcus =
	 * clientcustomerService.getCount(orgMsg); for (int j = 1; j <= clientcus /
	 * 1000 + 1; j++) { PageHelper.startPage(j, 1000); List<Clientcustomer>
	 * clientcustomer = (List<Clientcustomer>) clientcustomerService
	 * .selectByMsg(orgMsg); for (int k = 0; k < clientcustomer.size(); k++) {
	 * clientList.add(clientcustomer.get(k).getOrgId()); } } orgMsg.clear(); } }
	 * dataSource.clear(); orgMsg.clear(); List<OutOrder> allOrd = new
	 * ArrayList<OutOrder>(); Map<String, Object> allOrderPoint = new
	 * HashMap<String, Object>(); int allCount = 0; List<Order> odl = new
	 * ArrayList<Order>(); for (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); }
	 * 
	 * if (odl.size() == 0) { allCount = orderService.getCount(orgMsg); total +=
	 * allCount; if (allCount > 100 * (num - 1) && page > 0) {
	 * PageHelper.startPage(num, page); odl = (List<Order>)
	 * orderService.selectByMsg(orgMsg);
	 * 
	 * } orgMsg.clear(); List<String> ordList = new ArrayList<String>(); for
	 * (int j = 0; j < odl.size(); j++) { ordList.add(odl.get(j).getBillId()); }
	 * if (ordList.size() > 0) { orgMsg.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg.put("ordList", ordList); }
	 * 
	 * } List<OutOrder> rol = (List<OutOrder>) outOrderService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource());
	 * List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource()); // 加载主表数据
	 * for (int x = 0; x < rol.size(); x++) { if
	 * (!allOrderPoint.containsKey(rol.get(x).getSrcBillId())) {
	 * allOrd.add(rol.get(x)); allOrderPoint.put(rol.get(x).getSrcBillId(),
	 * allOrd.size() - 1); } } for (int x = 0; x < roil.size(); x++) { if
	 * (allOrd .get((int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).getItems() == null) { List<OutOrderItem> roitemp = new
	 * ArrayList<OutOrderItem>(); roitemp.add(roil.get(x)); allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).setItems(roitemp); } else
	 * { List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
	 * roitemp.addAll(allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).getItems()); roitemp.add(roil.get(x)); allOrd.get(
	 * (int) allOrderPoint.get(roil.get(x) .getSrcBillId())).setItems(roitemp);
	 * }
	 * 
	 * } page = page - allOrd.size(); num = 1; } else { num = num - allCount /
	 * 100; } }
	 * 
	 * System.out.println(allOrd.toString()); return
	 * ServerResponse.createBySuccess("获取出库单成功", allOrd); // } }
	 */

	/*
	 * @GetMapping("/getOutOrder")
	 * 
	 * @ResponseBody public Object getOutOrder(@RequestParam(required = false)
	 * String json, HttpServletRequest request) { String transToken =
	 * request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else { List<Erpkind> resultErpKind
	 * = erpkindService.selectList(null); Set<String> dataSource = new
	 * HashSet<String>(); List<String> clientList = new ArrayList<String>(); for
	 * (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { Map<String,
	 * Object> orgMsg = new HashMap<String, Object>(); orgMsg.put("clientId",
	 * clientId); orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
	 * List<Clientcustomer> clientcustomer = (List<Clientcustomer>)
	 * clientcustomerService .selectByMsg(orgMsg);
	 * 
	 * for (int j = 0; j < clientcustomer.size(); j++) {
	 * clientList.add(clientcustomer.get(j).getOrgId()); } orgMsg.clear(); } }
	 * dataSource.clear(); List<OutOrder> allOrd = new ArrayList<OutOrder>();
	 * Map<String, Object> allOrderPoint = new HashMap<String, Object>();
	 * 
	 * for (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { Map<String,
	 * Object> orgMsg = new HashMap<String, Object>();
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); } List<Order> odl = (List<Order>) orderService.selectByMsg(
	 * orgMsg, resultErpKind.get(i).getDataSource()); orgMsg.clear();
	 * List<String> ordList = new ArrayList<String>(); for (int j = 0; j <
	 * odl.size(); j++) { ordList.add(odl.get(j).getBillId()); } if
	 * (ordList.size() > 0) { orgMsg.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg.put("ordList", ordList); }
	 * List<OutOrder> rol = (List<OutOrder>) outOrderService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource());
	 * List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource()); // 加载主表数据
	 * for (int x = 0; x < rol.size(); x++) { if
	 * (!allOrderPoint.containsKey(rol.get(x).getSrcBillId())) {
	 * allOrd.add(rol.get(x));
	 * allOrderPoint.put(rol.get(x).getSrcBillId(),allOrd.size()-1); } } for
	 * (int x = 0; x < roil.size(); x++) { if (allOrd.get((int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).getItems() == null) {
	 * List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).setItems(roitemp); } else { List<OutOrderItem> roitemp
	 * = new ArrayList<OutOrderItem>(); roitemp.addAll(allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).getItems());
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).setItems(roitemp); }
	 * 
	 * 
	 * }
	 * 
	 * } }
	 * 
	 * System.out.println(allOrd.toString()); return
	 * ServerResponse.createBySuccess( "获取出库单成功", allOrd) ; } }
	 * 
	 * @GetMapping("/getOutOrder")
	 * 
	 * @ResponseBody public Object getOutOrder(@RequestParam(required = false)
	 * String json, HttpServletRequest request) { List<Erpkind> resultErpKind =
	 * erpkindService.selectList(null); Set<String> dataSource = new
	 * HashSet<String>(); List<String> clientList = new ArrayList<String>(); for
	 * (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { Map<String,
	 * Object> orgMsg = new HashMap<String, Object>(); orgMsg.put("clientId",
	 * "lyytest"); orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
	 * List<Clientcustomer> clientcustomer = (List<Clientcustomer>)
	 * clientcustomerService .selectByMsg(orgMsg);
	 * 
	 * for (int j = 0; j < clientcustomer.size(); j++) {
	 * clientList.add(clientcustomer.get(j).getOrgId()); } orgMsg.clear(); } }
	 * dataSource.clear(); List<OutOrder> allOrd = new ArrayList<OutOrder>();
	 * Map<String, Object> allOrderPoint = new HashMap<String, Object>();
	 * 
	 * for (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { Map<String,
	 * Object> orgMsg = new HashMap<String, Object>();
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); } List<Order> odl = (List<Order>) orderService.selectByMsg(
	 * orgMsg, resultErpKind.get(i).getDataSource()); orgMsg.clear();
	 * List<String> ordList = new ArrayList<String>(); for (int j = 0; j <
	 * odl.size(); j++) { ordList.add(odl.get(j).getBillId()); } if
	 * (ordList.size() > 0) { orgMsg.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg.put("ordList", ordList); }
	 * List<OutOrder> rol = (List<OutOrder>) outOrderService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource());
	 * List<OutOrderItem> roil = (List<OutOrderItem>) outOrderItemService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource()); // 加载主表数据
	 * for (int x = 0; x < rol.size(); x++) { if
	 * (!allOrderPoint.containsKey(rol.get(x).getSrcBillId())) {
	 * allOrd.add(rol.get(x));
	 * allOrderPoint.put(rol.get(x).getSrcBillId(),allOrd.size()-1); } } for
	 * (int x = 0; x < roil.size(); x++) { if (allOrd .get((int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).getOoi() == null) {
	 * List<OutOrderItem> roitemp = new ArrayList<OutOrderItem>();
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).setOoi(roitemp); } else { List<OutOrderItem> roitemp =
	 * new ArrayList<OutOrderItem>(); roitemp.addAll(allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getSrcBillId())).getOoi());
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getSrcBillId())).setOoi(roitemp); } ;
	 * 
	 * }
	 * 
	 * } }
	 * 
	 * System.out.println(allOrd.toString()); return allOrd; }
	 */
	/*
	 * 2018-12-23 23:26:02
	 */
	/*
	 * @GetMapping("/getBackOrder")
	 * 
	 * @ResponseBody public Object getBackOrder(@RequestParam(required = false)
	 * String orgId,
	 * 
	 * @RequestParam(required = false) String pageNum,
	 * 
	 * @RequestParam(required = false) String lastDate, HttpServletRequest
	 * request) {
	 * 
	 * String transToken = request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else {
	 * 
	 * 
	 * int num = 1; int page = 100; int total = 0;
	 * 
	 * if (!StringUtils.isBlank(pageNum) && Integer.parseInt(pageNum) > 0) { num
	 * = Integer.parseInt(pageNum); } Map<String, Object> orgMsg = new
	 * HashMap<String, Object>(); if (!StringUtils.isBlank(lastDate)) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * 
	 * try { orgMsg.put("lastDate", sdf.parse(lastDate)); } catch
	 * (ParseException e) { throw new AuthenticationException("传入日期格式错误"); } }
	 * 
	 * int preCount = (num - 1) * 100;
	 * 
	 * List<Erpkind> resultErpKind = erpkindService.selectList(null);
	 * Set<String> dataSource = new HashSet<String>(); List<String> clientList =
	 * new ArrayList<String>();
	 * 
	 * List<BackOrder> allOrd = new ArrayList<BackOrder>(); Map<String, Object>
	 * allOrderPoint = new HashMap<String, Object>(); List<String> ordList = new
	 * ArrayList<String>();
	 * 
	 * orgMsg.put("clientId", "guorenclient");
	 * 
	 * if (!StringUtils.isBlank(orgId)) {
	 * 
	 * orgMsg.put("orgId", orgId); } orgMsg.put("count", "guorenclient"); int
	 * clientcus = clientcustomerService.getCount(orgMsg); for (int i = 0; i <
	 * resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { int tempCount =
	 * backOrderService.getCount(orgMsg, resultErpKind .get(i).getDataSource());
	 * total += tempCount; } } orgMsg.remove("count"); dataSource.clear();
	 * 
	 * for (int j = num; j <= clientcus / 100 + 1; j++) {
	 * PageHelper.startPage(j, 1000); List<Clientcustomer> clientcustomer =
	 * (List<Clientcustomer>) clientcustomerService .selectByMsg(orgMsg); for
	 * (int k = 0; k < clientcustomer.size(); k++) {
	 * clientList.add(clientcustomer.get(k).getOrgId()); }
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); }
	 * 
	 * 
	 * for (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); } int countBol = backOrderService.getCount(orgMsg,
	 * resultErpKind.get(i).getDataSource()); if (preCount >= countBol) {
	 * preCount = preCount - countBol; break; }
	 * 
	 * List<BackOrder> bol = (List<BackOrder>) backOrderService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource());
	 * orgMsg.clear();
	 * 
	 * 
	 * for (int k = 0; k < bol.size(); k++) {
	 * ordList.add(bol.get(k).getBillId()); }
	 * 
	 * 
	 * // 加载主表数据 for (int x = preCount; x < bol.size(); x++) { if (allOrd.size()
	 * >= 100) { break; } if
	 * (!allOrderPoint.containsKey(bol.get(x).getBillId())) {
	 * allOrd.add(bol.get(x)); allOrderPoint.put(bol.get(x).getBillId(),
	 * allOrd.size() - 1); ordList.add(bol.get(x).getBillId()); } }
	 * 
	 * } } preCount = 0; dataSource.clear(); if (ordList.size() > 0) {
	 * orgMsg.put("ordList", ordList); } else {
	 * ordList.add("clientproductprice"); orgMsg.put("ordList", ordList); } for
	 * (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * List<BackOrderItem> roil = (List<BackOrderItem>) backOrderItemService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource()); for (int x =
	 * 0; x < roil.size(); x++) { if (allOrd.get( (int) allOrderPoint
	 * .get(roil.get(x).getBillId())).getBoi() == null) { List<BackOrderItem>
	 * roitemp = new ArrayList<BackOrderItem>(); roitemp.add(roil.get(x));
	 * allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getBillId())).setBoi(roitemp); } else { List<BackOrderItem> roitemp =
	 * new ArrayList<BackOrderItem>(); roitemp.addAll(allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getBillId())).getBoi());
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getBillId())).setBoi(roitemp); } ;
	 * 
	 * } } } } ResponseData rd = new ResponseData(); if (total % 100 > 0) {
	 * rd.setTotal((total / 100) + 1); } else { rd.setTotal(allOrd.size() /
	 * 100); } rd.setRows((ArrayList) allOrd);
	 * 
	 * System.out.println(allOrd.toString()); return
	 * ServerResponse.createBySuccess("获取退货单成功", rd); // } }
	 */

	/*
	 * @GetMapping("/getBackOrder")
	 * 
	 * @ResponseBody public Object getBackOrder(@RequestParam(required = false)
	 * String json, HttpServletRequest request) { String transToken =
	 * request.getHeader("Authorization"); String clientId =
	 * request.getHeader("client_id"); // 判断token是否合法 if
	 * (StringUtils.isBlank(CacheUtil.get(transToken, transToken))) { // return
	 * // ServerResponse.createByErrorMessage("Token验证失败，请重新获取Token信息"); throw
	 * new AuthenticationException("未登录"); } else { List<Erpkind> resultErpKind
	 * = erpkindService.selectList(null); Set<String> dataSource = new
	 * HashSet<String>(); List<String> clientList = new ArrayList<String>(); for
	 * (int i = 0; i < resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) { Map<String,
	 * Object> orgMsg = new HashMap<String, Object>(); orgMsg.put("clientId",
	 * clientId); orgMsg.put("dataType", resultErpKind.get(i).getAccountId());
	 * List<Clientcustomer> clientcustomer = (List<Clientcustomer>)
	 * clientcustomerService .selectByMsg(orgMsg);
	 * 
	 * for (int j = 0; j < clientcustomer.size(); j++) {
	 * clientList.add(clientcustomer.get(j).getOrgId()); } orgMsg.clear(); } }
	 * dataSource.clear(); List<BackOrder> allOrd = new ArrayList<BackOrder>();
	 * Map<String, Object> allOrderPoint = new HashMap<String, Object>();
	 * List<String> ordList = new ArrayList<String>(); Map<String, Object>
	 * orgMsg = new HashMap<String, Object>(); for (int i = 0; i <
	 * resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * 
	 * if (clientList.size() > 0) { orgMsg.put("clientList", clientList); } else
	 * { clientList.add("clientproductprice"); orgMsg.put("clientList",
	 * clientList); }
	 * 
	 * List<BackOrder> bol = (List<BackOrder>) backOrderService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource());
	 * orgMsg.clear();
	 * 
	 * for (int j = 0; j < bol.size(); j++) {
	 * ordList.add(bol.get(j).getBillId()); }
	 * 
	 * // 加载主表数据 for (int x = 0; x < bol.size(); x++) { if
	 * (!allOrderPoint.containsKey(bol.get(x).getBillId())) {
	 * allOrd.add(bol.get(x)); allOrderPoint.put(bol.get(x).getBillId(),
	 * allOrd.size() - 1); } }
	 * 
	 * } } dataSource.clear(); if (ordList.size() > 0) { orgMsg.put("ordList",
	 * ordList); } else { ordList.add("clientproductprice");
	 * orgMsg.put("ordList", ordList); } for (int i = 0; i <
	 * resultErpKind.size(); i++) { if
	 * (dataSource.add(resultErpKind.get(i).getDataSource())) {
	 * List<BackOrderItem> roil = (List<BackOrderItem>) backOrderItemService
	 * .selectByMsg(orgMsg, resultErpKind.get(i) .getDataSource()); for (int x =
	 * 0; x < roil.size(); x++) { if (allOrd.get( (int) allOrderPoint
	 * .get(roil.get(x).getBillId())).getBoi() == null) { List<BackOrderItem>
	 * roitemp = new ArrayList<BackOrderItem>(); roitemp.add(roil.get(x));
	 * allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getBillId())).setBoi(roitemp); } else { List<BackOrderItem> roitemp =
	 * new ArrayList<BackOrderItem>(); roitemp.addAll(allOrd.get( (int)
	 * allOrderPoint.get(roil.get(x) .getBillId())).getBoi());
	 * roitemp.add(roil.get(x)); allOrd.get( (int) allOrderPoint.get(roil.get(x)
	 * .getBillId())).setBoi(roitemp); } ;
	 * 
	 * } } }
	 * 
	 * ResponseData rd = new ResponseData(); rd.setTotal(allOrd.size());
	 * rd.setRows((ArrayList) allOrd);
	 * System.out.println(JSON.toJSONString(rd));
	 * 
	 * // System.out.println(request.getHeader("Authorization")); //
	 * System.out.println(request.getHeader("client_id")); return
	 * ServerResponse.createBySuccess("获取退货单成功", rd);
	 * 
	 * } }
	 */

	public Map<String, String> jsonToMap(String json) {
		return (Map<String, String>) JSON.parse(json);
	}

	

	@GetMapping("/dosth")
	@ResponseBody
	public ServerResponse getdosth(@RequestParam String username,
			@RequestParam String age, @RequestParam String bbb,
			HttpServletRequest request) {
		System.out.println(request.getHeader("client_id"));

		// R finalResponse = new R<>("get this is blog username:" +
		// username+" age:"+age+" bbb:"+bbb);
		return ServerResponse
				.createBySuccessMessage("get this is blog username:" + username
						+ " age:" + age + " bbb:" + bbb);
	}

	@PutMapping("/dosth")
	@ResponseBody
	public ServerResponse putdosth(@RequestBody String json,
			HttpServletRequest request) {
		System.out.println(request.getHeader("client_id"));
		ClientCheck user = new ClientCheck();
		user.setGrant_type("lyy");
		user.setClient_id("lyy1");
		user.setClient_secret("123456");
		// R finalResponse = new R<>(user);
		return ServerResponse.createBySuccess("成功", user);
	}

	@PostMapping("/dosth")
	@ResponseBody
	public ServerResponse postdosth(@RequestBody String json,
			HttpServletRequest request) {
		System.out.println(request.getHeader("client_id"));
		ClientCheck user = new ClientCheck();
		user.setGrant_type("lyy");
		user.setClient_id("lyy1");
		user.setClient_secret("123456");
		// R finalResponse = new R<>(user);
		return ServerResponse.createBySuccess("成功", user);
	}

	@DeleteMapping("/dosth")
	@ResponseBody
	public ServerResponse deletedosth(@RequestParam String username,
			@RequestParam String age, @RequestParam String bbb,
			HttpServletRequest request) {
		System.out.println(request.getHeader("client_id"));
		return ServerResponse
				.createBySuccessMessage("delete this is blog username:"
						+ username + " age:" + age + " bbb:" + bbb);
	}

	@GetMapping("/common")
	@ResponseBody
	public Object common(HttpServletRequest request) throws IOException{
		
		String path=Thread.currentThread().getContextClassLoader().getResource("").getPath()+"static/modular/ry600/common.properties";
		this.getMsg(path);
		ArrayList<Object> client_id=new ArrayList<Object>();
		client_id.add("guoren");
		client_id.add("guoren1");
		ArrayList<Object> client_id1=new ArrayList<Object>();
		client_id1.add("");
		client_id1.add("X333");
		//包装一个功能名称
		ArrayList<Object> client_id2=new ArrayList<Object>();
		client_id2.add("test");
		Map<String,String> test1=new HashMap<String,String>();
		test1.put("lyytest", "6666");
		client_id2.add(test1);
		Map<String, ArrayList<Object>> msg=new HashMap<String,ArrayList<Object>>();
		msg.put("A", client_id1);
		msg.put("B", client_id);
		ArrayList<Object> page=new ArrayList<Object>();
		page.add(2);
		msg.put("page", page);
		//固定key传入包装好的功能名称
		msg.put("nexTpluginName", client_id2);
		Map<String,ArrayList<Object>> resultMsg=new HashMap<String,ArrayList<Object>>();
		this.realDo(msg,resultMsg);
		return resultMsg;
	}
	/**
	 * 真实业务解释
	 * @param msg
	 * @return
	 */
	public void realDo(Map<String,ArrayList<Object>> origMsg,Map<String,ArrayList<Object>> resultMsg){
		//把传入参数的key转换为小写
		Map<String,ArrayList<Object>> msg=new HashMap<String,ArrayList<Object>>();
		int page=1;
		Iterator it3=origMsg.keySet().iterator();
		while(it3.hasNext()){
			String it3temp=(String) it3.next();
			msg.put(it3temp.toLowerCase(), origMsg.get(it3temp));
			if("page".equals(it3temp.toLowerCase()) && (int)origMsg.get("page").get(0)>0){
				page=(int)origMsg.get("page").get(0);
			}
		}
		int preCount=(page-1)*100;
		//获取当前需要读取的功能名称
		String plugin=(String) msg.get("nexTpluginName".toLowerCase()).get(0);
		Map<String,String> plug=rela.get(plugin);
		
		//返回的参数
		//Map<String, ArrayList<Object>> returnMsg=new HashMap<String,ArrayList<Object>>();
		//传递的参数
		Map<String, ArrayList<Object>> passMsg=new HashMap<String,ArrayList<Object>>();
		
		Set<String> plugKeystemp=plug.keySet();
		TreeSet<String> plugKeys=new TreeSet<String>();
		plugKeys.addAll(plugKeystemp);
		/*
		 * 读取输入参数
		 */
		Set<String> msgKey=msg.keySet();//获取真实输入参数的key
		Set<String> msgPreKey=new HashSet<String>();
		Iterator it2=msgKey.iterator();
		while(it2.hasNext()){
			String it2temp=(String) it2.next();
			msgPreKey.add(it2temp.toLowerCase());
		}
		//获取模板里面的输入参数的key
		Set<String> plugPreKey=new HashSet<String>();
		if(plug.containsKey("preParameter".toLowerCase())){
			System.out.println(JSONObject.toJSONString(msg));
			List<Object> li=JSON.parseArray(plug.get("preParameter".toLowerCase()));
			for(int i=0;i<li.size();i++){
				plugPreKey.add((String)li.get(i));
			}
		}
		//获取真正使用的参数
		List<String> realPrePar=new ArrayList<String>();
		List<String> realPreParTemp=new ArrayList<String>();
		Iterator it1=plugPreKey.iterator();
		while(it1.hasNext()){
			String plugPreKeyReal=(String)it1.next();
			String plugPreKeyTemp=plugPreKeyReal.replace("%", "");
			if(msgPreKey.contains(plugPreKeyTemp)){
				realPreParTemp.add(plugPreKeyTemp);
				realPrePar.add(plugPreKeyReal);
			}
		}
		
		//循环获取所有的sql语句
		Map<String,String> sqls=new HashMap<String,String>();
		Iterator it=plugKeys.iterator();
		while(it.hasNext()){
			String plugKey=(String) it.next();
			if(plugKey.startsWith("exqSql".toLowerCase())){
				//获取到脚本
				//sqls.put(plugKey, plug.get(plugKey));
				String exSql=plug.get(plugKey);
				//把参数注入获取到的脚本
				while(exSql.indexOf("#")>0){
					if(plug.containsKey("needpar"+plugKey)&&"true".equals(plug.get("needpar"+plugKey))){
						exSql=this.replace(exSql, realPrePar,realPreParTemp,msg,true);
					}else{
						exSql=this.replace(exSql, realPrePar,realPreParTemp,msg,false);
					}
				};
				//封裝查询语句
				int temppoint=0;
				if(exSql.indexOf(",")>0){
					temppoint=exSql.indexOf(",");
				}else{
					temppoint=exSql.indexOf("from");
				}
				exSql="select ROW_NUMBER() OVER(Order by "+exSql.substring(6, temppoint).trim()+" ) as rowid, "+exSql.substring(6);
				Map<String,String> getCount=new HashMap<String,String>();
				
				
				//获取需要执行的数据源
				Set<String> dataSources=new HashSet<String>();
				if(plug.containsKey("datasource"+plugKey)){
					List<Object> dataSourceLi=JSON.parseArray(plug.get("datasource"+plugKey.toLowerCase()));
					for(int i=0;i<dataSourceLi.size();i++){
						dataSources.add((String)dataSourceLi.get(i));
					}
				}
				//根据数据源遍历获取数据，如果不设置数据源则默认主数据源
				List<String> dataSourceFinal=new ArrayList<String>();//防止重复账套查询
				dataSourceFinal.addAll(dataSources);
				if(dataSourceFinal.size()>0){
					//调用真实业务接口
					for(int j=0;j<dataSourceFinal.size();j++){
						
						List<Map<String, String>> test=new ArrayList<Map<String,String>>();
						//分页功能
						if(plug.containsKey("usepage"+plugKey)&&"true".equals(plug.get("usepage"+plugKey))){
							if(resultMsg.containsKey(plugin+"_"+plugKey)){
								if(resultMsg.get(plugin+"_"+plugKey).size()>=100){
									break;
								}
							}
							String getCountSql="select count(*)  from ("+exSql+")mx";
							Map<String,String> sqlMsg=new HashMap<String,String>();
							sqlMsg.put("sql", getCountSql);
							int count=commonService.selectCount(sqlMsg, dataSourceFinal.get(j));
							if(count>preCount){
								exSql="select * from  ("+exSql+")mx where rowid between "+ ((page-1)*100+1) +" and " + page*100;
								sqlMsg.put("sql", exSql);
							}else{
								preCount=preCount-count;
								break;
							}
							test=commonService.selectByMsg(sqlMsg, dataSourceFinal.get(j));
						}else{
							Map<String,String> sqlMsg=new HashMap<String,String>();
							sqlMsg.put("sql", exSql);
							test=commonService.selectByMsg(sqlMsg, dataSourceFinal.get(j));
						}
						if(test.size()>0){
							//参数向下传递
							if(plug.containsKey("pass"+plugKey)&&"true".equals(plug.get("pass"+plugKey))){
								if(passMsg.containsKey(plugin+"_"+plugKey)){
									ArrayList<Object> testtemp=new ArrayList<Object>();
									for(int l=0;l<test.size();l++){
										Map<String,String> testtepmm=test.get(l);
										testtepmm.remove("rowid");
										testtemp.add(testtepmm);
									}
									passMsg.get(plugin+"_"+plugKey).addAll(testtemp);
								}else{
									ArrayList<Object> testtemp=new ArrayList<Object>();
									for(int l=0;l<test.size();l++){
										Map<String,String> testtepmm=test.get(l);
										testtepmm.remove("rowid");
										testtemp.add(testtepmm);
									}
									passMsg.put(plugin+"_"+plugKey,  testtemp);
								}
							}
							//结果返回
							if(plug.containsKey("return"+plugKey)&&"true".equals(plug.get("return"+plugKey))){
								if(resultMsg.containsKey(plugin+"_"+plugKey)){
									ArrayList<Object> testtemp=new ArrayList<Object>();
									for(int l=0;l<test.size();l++){
										Map<String,String> testtepmm=test.get(l);
										testtepmm.remove("rowid");
										testtemp.add(testtepmm);
									}
									resultMsg.get(plugin+"_"+plugKey).addAll(testtemp);
								}else{
									ArrayList<Object> testtemp=new ArrayList<Object>();
									for(int l=0;l<test.size();l++){
										Map<String,String> testtepmm=test.get(l);
										testtepmm.remove("rowid");
										testtemp.add(testtepmm);
									}
									resultMsg.put(plugin+"_"+plugKey,  testtemp);
								}
							}
							System.out.println(test);
						}
					}
				}
			}
			//语句之后进入的业务分支
			if(plug.containsKey("nextplugin"+plugKey)){
				ArrayList<Object> client_id=new ArrayList<Object>();
				client_id.add(plug.get("nextplugin"+plugKey));
				passMsg.put("nexTpluginName", client_id);
				this.realDo(passMsg, resultMsg);
			}
		}
		//把输入参数向下传递
		if(plug.containsKey("passpreParameter".toLowerCase())&&"true".equals(plug.get("passpreParameter".toLowerCase()))){
			passMsg.putAll(origMsg);
		}
		//调用下一个功能
		if(plug.containsKey("nexTpluginName".toLowerCase())&&rela.containsKey(plug.get("nexTpluginName".toLowerCase()))){
			ArrayList<Object> client_id=new ArrayList<Object>();
			client_id.add(plug.get("nexTpluginName".toLowerCase()));
			passMsg.put("nexTpluginName", client_id);
			this.realDo(passMsg, resultMsg);
		}
	}
	/**
	 * 
	 * @param sql 需转换sql
	 * @param realMsg 真实逻辑参数
	 * @param tempMsg 参数模板
	 * @param data 数据实体
	 * @return
	 */
	public String replace(String sql,List<String> realMsg,List<String> tempMsg,Map<String,ArrayList<Object>> data,Boolean bl){
		int index=sql.indexOf("#");
		int nextIndex=sql.indexOf("#", index+1);
		String par=sql.substring(index+1, nextIndex).trim();
		String parTemp=par;
		if(par.indexOf("[")>0){
			parTemp=par.substring(0, par.indexOf("["));
		}
		if(bl=true || tempMsg.contains(parTemp)){
			//真实注入操作
			System.out.println(tempMsg.indexOf(parTemp));
			//确定参数所在列表位置
			int pointMsg=tempMsg.indexOf(parTemp);
				
			
				int ifGet=0;
				int place=index;
				int place1=index;
				while(ifGet<3){
					if("=".equals(sql.subSequence(place-1, place))){
						ifGet++;
						place1=place-1;
						place--;
					}
					if(ifGet==1&&!" ".equals(sql.subSequence(place-1, place))){
						ifGet++;
						place--;
					}
					if(ifGet==2&&" ".equals(sql.subSequence(place-1, place))){
						ifGet++;
					}
					if(place<1){
						place=4;
					}
					if(ifGet<3){
						place--;
					}
//					System.out.println(sql.substring(place, nextIndex+1));
				}
			//ifGet==3标识该位置为参数开始位置
				if(ifGet==3){
					//获取到正确的查询条件
					String whereSql=sql.substring(place, nextIndex+1).trim();//完整查询条件
					String parSql=sql.substring(place,place1).trim();//查询条件名称
					if(pointMsg<0){
						int finLen=sql.length()-nextIndex;
						String whereSqltemp="";
						if(finLen>5){
							whereSqltemp=sql.substring(place-4, nextIndex+5).trim();
						}else{
							whereSqltemp=sql.substring(place-4, nextIndex+finLen).trim();
						}
						String returnSql="";
						if(whereSqltemp.startsWith("and")&&whereSqltemp.endsWith("and")){
							returnSql=sql.replace(whereSqltemp, "and");
						}else if(whereSqltemp.startsWith("and")&&!whereSqltemp.endsWith("and")){
							if(whereSqltemp.lastIndexOf(" ")>4){
								returnSql=sql.replace(whereSqltemp.substring(0, whereSqltemp.lastIndexOf(" ")), "");
							}else{
								returnSql=sql.replace(whereSqltemp, "");
							}
						}else if(!whereSqltemp.startsWith("and")&&whereSqltemp.endsWith("and")){
//							System.out.println(whereSqltemp.indexOf(" "));
//							System.out.println(whereSqltemp.length());
							returnSql=sql.replace(whereSqltemp.substring(whereSqltemp.indexOf(" "),whereSqltemp.length()), "");
						}else{
							if(whereSqltemp.lastIndexOf(" ")>4){
								returnSql=sql.replace(whereSqltemp.substring(whereSqltemp.indexOf(" "), whereSqltemp.lastIndexOf(" ")), "");
							}else{
								String whereSqltemp1="";
								if(finLen>5){
									whereSqltemp1=sql.substring(place-6, nextIndex+5).trim();
								}else{
									whereSqltemp1=sql.substring(place-6, nextIndex+finLen).trim();
								}
								if(whereSqltemp1.startsWith("where")){
									returnSql=sql.replace(whereSqltemp1, "");
								}else{
									returnSql=sql.replace(whereSqltemp.substring(whereSqltemp.indexOf(" "), whereSqltemp.length()), "");
								}
							}
						}
						
						return returnSql;
					}
					
					String finalSql="";
					//处理模糊查询的参数
					if(realMsg.get(pointMsg).endsWith("%")||realMsg.get(pointMsg).startsWith("%")){
					//获取真实数据参数
						for(int i=0;i<data.get(parTemp).size();i++){
							if(i>0){
								finalSql+=" or ";
							}else{
								finalSql+="(";
							}
							String tempSql="";
							if(whereSql.indexOf("[")>0 && whereSql.indexOf("]")>0){
								tempSql=((Map<String,String>)data.get(parTemp).get(i)).get(whereSql.substring(whereSql.indexOf("[")+1, whereSql.indexOf("]")));
							}else if(whereSql.indexOf("[")<0 && whereSql.indexOf("]")<0){
								tempSql=(String) data.get(par).get(i);
							}else{
								throw new NotAuthedException("sql注入参数格式错误"); 
							}
							if(realMsg.get(pointMsg).endsWith("%")){
								tempSql="%"+tempSql;
							}
							if(realMsg.get(pointMsg).startsWith("%")){
								tempSql=tempSql+"%";
							}
							finalSql+=parSql + " like " +"'"+tempSql+"'";
						}
				
					}
					//非模糊查询
					else{
						for(int i=0;i<data.get(parTemp).size();i++){
							if(i>0){
								finalSql+=",";
							}else{
								finalSql+=parSql +" in (";
							}
							String tempSql="";
							
							if(whereSql.indexOf("[")>0 && whereSql.indexOf("]")>0){
								System.out.println(whereSql.substring(whereSql.indexOf("[")+1, whereSql.indexOf("]")));
								tempSql=((Map<String,String>)data.get(parTemp).get(i)).get(whereSql.substring(whereSql.indexOf("[")+1, whereSql.indexOf("]")));
							}else if(whereSql.indexOf("[")<0 && whereSql.indexOf("]")<0){
								tempSql=(String) data.get(par).get(i);
							}else{
								throw new NotAuthedException("sql注入参数格式错误"); 
							}
							
							finalSql+="'"+tempSql+"'";
						}
					}
					String returnSql=sql.replace(whereSql, finalSql+")");
					return returnSql;
				}
			
		}else{
			throw new NotAuthedException("sql注入参数缺失"); 
		}
		System.out.println(par);
		return sql;
	}
	
	/**
	 * 加载业务关系表，数据存放rela全局变量
	 * @param path
	 * @return
	 * @throws IOException
	 */
	public String getMsg(String path) throws IOException {
		String REGEX1 = "}";
		String REGEX2 = ";";
		String REGEX3 = ":";
		String PREFIX = "{";
		String TOPIC="pluginName";
		
				System.out.println("从配置文件加载业务关系");
				BufferedReader br = null;
				String sb = "";
				try {
					br = new BufferedReader(new InputStreamReader(
							new FileInputStream(path), "UTF-8"));
					String str;
					while ((str = br.readLine()) != null) {
						if (!str.trim().startsWith("#")
								&& !"".equals(str.trim())) {
							sb += str;
						}
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				} finally {
					br.close();
				}
				
				String[] sl = sb.split(REGEX1);
				for (int i = 0; i < sl.length; i++) {
					// System.out.println(i+":"+sl[i].toString());
					if (sl[i].startsWith(PREFIX) && sl[i].trim().length() > 1) {
						sl[i] = sl[i].substring(1, sl[i].length());
						Map<String, String> mp = new HashMap<String, String>();
						String mn = "";
						String[] ss = sl[i].split(REGEX2);
						if (ss.length > 0) {
							for (int j = 0; j < ss.length; j++) {
								String[] sm = ss[j].trim().split(REGEX3);
								if (sm.length == 2) {
									//排除中文空格干扰
									mp.put(sm[0].trim().toLowerCase(), sm[1].replaceAll(" +", " ").replace(System.getProperty("line.separator"), " ").trim().toLowerCase());
									if (TOPIC.toLowerCase().equals(
											sm[0].toLowerCase())) {
										mn += sm[1].trim();
									}
								}
							}
						}
						if(!"".equals(mn)){
							rela.put(mn.toLowerCase(), mp);
						}
					}

				}


				return sb;
	}
	
	
	/*@GetMapping("/test")
	@ResponseBody
	public Object test(@RequestParam(required = false) String json,
			HttpServletRequest request) {
		System.out.println(request.getHeader("Authorization"));
		System.out.println(request.getHeader("client_id"));
		return ServerResponse.createBySuccessMessage("lyy");
	}*/
	@GetMapping("/test")
	@ResponseBody
	public void test(
			HttpServletRequest request) throws Exception {
		  //这个Map用来为报表中的Parameter参数设置值
       /* Map<String, Object> parameters = new HashMap<String, Object>();
        //用来存一堆POJO对象的列表
        List<TestWater> students = new ArrayList<TestWater>();
        //添加一些用来生成报表的POJO对象
        for (int i = 0; i < 5; i++) {
            students.add(new TestWater( "name" + i,  i));
        }
        System.out.println("---[开始]---");
        //开始计时
        long startTime = System.currentTimeMillis();

        //[1]编译后的jasper文件位置
        String jasperFilePath = "E:/接口开发/佛山市节水统计问券调查/test.jasper";
        //[2]在Map中添加KV对,以用来设置参数
        parameters.put("author", "LiuZhiHao");
        //[3]传入放置了POJO对象的集合类列表,以建立数据源对象
        JRDataSource jrDataSource = new JRBeanCollectionDataSource(students);

        try {
            //将jasper资源、参数Map、数据源对象整合到一起,形成JasperPrint总资源对象
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperFilePath, parameters, jrDataSource);
            //字节数组输出流,用于输出成PDF
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            //PDF输出工具
            JRPdfExporter jrPdfExporter = new JRPdfExporter();
            //为输出工具组合插件
            jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);//总资源对象
            jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);//输出字节数组流
            jrPdfExporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");//编码 
            //导出,导出结束后会按照参数将结果放在输出字节数组流中
            jrPdfExporter.exportReport();

            //将其变成字节数组
            byte[] bytes=byteArrayOutputStream.toByteArray();
            //写出到文件
            File file=new File("E:/接口开发/佛山市节水统计问券调查/test.pdf");
            FileOutputStream fileOutputStream=new FileOutputStream(file);
            fileOutputStream.write(bytes);
            System.out.println("写入完毕");
            fileOutputStream.close();
        } catch (JRException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //结束计时
            long endTime=System.currentTimeMillis();
            System.out.println("---[结束]共用时"+(endTime-startTime)+"---");
        }
	}*/
		
		
		//excell转pdf

	       /* Document document = new Document(PageSize.A4,0,0,50,0);  
	        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/接口开发/佛山市节水统计问券调查/测试excell转pdf/附件1：佛山市节水统计报表.pdf"));  
	          
	        //字体设置    
	          
	         * 由于itext不支持中文，所以需要进行字体的设置，我这里让itext调用windows系统的中文字体，  
	         * 找到文件后，打开属性，将文件名及所在路径作为字体名即可。  
	             
	        //创建BaseFont对象，指明字体，编码方式,是否嵌入    
	        BaseFont bf=BaseFont.createFont("E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\simkai.ttf", BaseFont.IDENTITY_H, false);    
	        //创建Font对象，将基础字体对象，字体大小，字体风格    
	        Font font=new Font(bf,13,Font.NORMAL);    
	        int rowNum = 0;  
	        int colNum = 0;
	        try {  
	            Workbook workbook=Workbook.getWorkbook(new File("E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\附件1：佛山市节水统计报表.xls"));
	              
	            Sheet sheet=workbook.getSheet(1);  
	            int column=sheet.getColumns();  
	              
	            //下面是找出表格中的空行和空列  
	            List<Integer> nullCol = new ArrayList<>();  
	            List<Integer> nullRow = new ArrayList<>();  
	            for(int j=0;j<sheet.getColumns();j++){  
	                int nullColNum = 0;  
	                for(int i=0;i<sheet.getRows();i++){  
	                    Cell cell=sheet.getCell(j, i);  
	                    String str = cell.getContents();  
	                    if(str == null || "".equals(str)){  
	                        nullColNum ++ ;  
	                    }  
	                }  
	                if(nullColNum == sheet.getRows()){  
	                    nullCol.add(j);  
	                    column--;  
	                }  
	            }  
	              
	            for(int i=0;i<sheet.getRows();i++){  
	                int nullRowNum = 0;  
	                for(int j=0;j<sheet.getColumns();j++){  
	                    Cell cell=sheet.getCell(j, i);  
	                    String str = cell.getContents();  
	                    if(str == null || "".equals(str)){  
	                        nullRowNum ++ ;  
	                    }  
	                }  
	                if(nullRowNum == sheet.getColumns()){  
	                    nullRow.add(i);  
	                }  
	            }  
	            PdfPTable table=new PdfPTable(column);    
	            Range[] ranges = sheet.getMergedCells();  
	              
	            PdfPCell cell1=new PdfPCell();  
	            for(int i=0;i<sheet.getRows();i++){  
	                if(nullRow.contains(i)){    //如果这一行是空行，这跳过这一行  
	                    continue;  
	                }  
	                for(int j=0;j<sheet.getColumns();j++){  
	                    if(nullCol.contains(j)){    //如果这一列是空列，则跳过这一列  
	                        continue;  
	                    }  
	                    boolean flag = true;  
	                    Cell cell=sheet.getCell(j, i);  
	                    String str = cell.getContents();  
	                    for(Range range : ranges){    //合并的单元格判断和处理  
	                        if(j >= range.getTopLeft().getColumn() && j <= range.getBottomRight().getColumn()   
	                                && i >= range.getTopLeft().getRow() && i <= range.getBottomRight().getRow()){  
	                            if(str == null || "".equals(str)){  
	                                flag = false;  
	                                break;  
	                            }  
	                            rowNum = range.getBottomRight().getRow() - range.getTopLeft().getRow()+1;  
	                            colNum = range.getBottomRight().getColumn() - range.getTopLeft().getColumn()+1;  
	                            if(rowNum > colNum){  
	                                cell1 = mergeRow(str, font, rowNum);  
	                                cell1.setColspan(colNum);  
	                                table.addCell(cell1);  
	                            }else {  
	                                cell1 = mergeCol(str, font, colNum);  
	                                cell1.setRowspan(rowNum);  
	                                table.addCell(cell1);  
	                            }  
	                            //System.out.println(num1 + "  " + num2);  
	                            flag = false;  
	                            break;  
	                        }  
	                    }  
	                    if(flag){  
	                        table.addCell(getPDFCell(str,font));           
	                    }  
	                }  
	            }  
	              
	            workbook.close();  
	            document.open();        
	            document.add(table);    
	            document.close();    
	            writer.close();  
	        } catch (BiffException | IOException e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  */
	    /*调用windows组件转换excell-->pdf
		String path = "E:/接口开发/佛山市节水统计问券调查/测试excell转pdf/";
        this.excel2Pdf(path + "test.xls", path+ "test.pdf");*/
		/**
		 * 获取excell表数据
		 */
		 ExcellUtil excelUtil = new ExcellUtil();

	        //读取excel数据
	    /*    ArrayList<Map<String,String>> result = excelUtil.readExcelToObj("E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\template.xlsx");
	        for(Map<String,String> map:result){
	            System.out.println(map);
	     }*/
	   /**
	    * 修改excell表数据
	    */
		 /*excelUtil.copyFile("E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\test\\template.xlsx","E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\test");
          File file=new File("E:\\接口开发\\佛山市节水统计问券调查\\测试excell转pdf\\test\\jieguo.xlsx");
          excelUtil.updateExcel(file,0,2,12,"□机关   □写字楼   □科研机构  □医院   □宾馆饭店   □旅馆   □普通高校   □其他高等教育学校   □普通中等学校   □小学 ☑幼儿园   □餐饮   □商场  □乳品  □饮料  □化工  □制药  □钢铁  □机电   □电子  □电力  □建材  □汽车  □其它");      
          String path = "E:/接口开发/佛山市节水统计问券调查/测试excell转pdf/test/";
          excelUtil.excel2Pdf(path + "jieguo.xlsx", path+ "jieguo.pdf");*/
	}
	
	//操作excell表
	public static void generateExcelByTemplet() throws IOException, EncryptedDocumentException, InvalidFormatException{
		final String excelTempletPath = "E:/接口开发/佛山市节水统计问券调查/测试excell转pdf/template.xlsx";
		FileInputStream templetInputStream = new FileInputStream(excelTempletPath);
		/*XSSFWorkbook workbook=new XSSFWorkbook(templetInputStream);//得到文档对象
        XSSFSheet sheet=workbook.getSheet("用水单位基本信息");  //根据name获取sheet表
        XSSFRow startRow = sheet.getRow(7);
        System.out.println("内容："+startRow.getCell(0).getStringCellValue());*/
		Workbook workbook = null;
		workbook = WorkbookFactory.create(templetInputStream);
		templetInputStream.close();
        //工作表对象
        Sheet sheet = workbook.getSheetAt(0);
      //总行数
        int rowLength = sheet.getLastRowNum()+1;
        //工作表的列
        Row row = sheet.getRow(7);
        //总列数
        int colLength = row.getLastCellNum();
        //得到指定的单元格
        Cell cell = row.getCell(0);
        if (cell != null){
        	cell.setCellType(CellType.STRING);
//        	cell.setCellValue("1000");
        	System.out.print(cell.getStringCellValue() + "\t");
        }

		
	}
	
	
	//合并行的静态函数    
	public static PdfPCell mergeRow(String str,Font font,int i) {    
	        
	    //创建单元格对象，将内容及字体传入    
	    PdfPCell cell=new PdfPCell(new Paragraph(str,font));    
	    //设置单元格内容居中    
	    cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
	    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);    
	    //将该单元格所在列包括该单元格在内的i行单元格合并为一个单元格    
	    cell.setRowspan(i);    
	        
	    return cell;    
	}    
	
	//合并列的静态函数    
	public static PdfPCell mergeCol(String str,Font font,int i) {    
	        
	    PdfPCell cell=new PdfPCell(new Paragraph(str,font));    
	    cell.setMinimumHeight(25);    
	    cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
	    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);    
	    //将该单元格所在行包括该单元格在内的i列单元格合并为一个单元格    
	    cell.setColspan(i);    
	        
	    return cell;    
	}    
	  
	 //获取指定内容与字体的单元格    
	public static PdfPCell getPDFCell(String string, Font font)     
	{    
	    //创建单元格对象，将内容与字体放入段落中作为单元格内容    
	    PdfPCell cell=new PdfPCell(new Paragraph(string,font));    
	        
	    cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
	    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);    
	        
	    //设置最小单元格高度    
	    cell.setMinimumHeight(25);    
	    return cell;    
	}   
	
	
	public void excel2Pdf(String inFilePath, String outFilePath) throws Exception {
	 	final Integer WORD_TO_PDF_OPERAND = 17;
	    final Integer PPT_TO_PDF_OPERAND = 32;
	    final Integer EXCEL_TO_PDF_OPERAND = 0;
        ActiveXComponent ax = null;
        Dispatch excel = null;
        try {
            ComThread.InitSTA();
            ax = new ActiveXComponent("Excel.Application");
            ax.setProperty("Visible", new Variant(false));
            ax.setProperty("AutomationSecurity", new Variant(3)); // 禁用宏
            Dispatch excels = ax.getProperty("Workbooks").toDispatch();

            Object[] obj = new Object[]{ 
                    inFilePath, 
                    new Variant(false),
                    new Variant(false) 
             };
            excel = Dispatch.invoke(excels, "Open", Dispatch.Method, obj, new int[9]).toDispatch();
            
            // 转换格式
            Object[] obj2 = new Object[]{ 
                    new Variant(EXCEL_TO_PDF_OPERAND), // PDF格式=0
                    outFilePath, 
                    new Variant(0)  //0=标准 (生成的PDF图片不会变模糊) ; 1=最小文件
            };
            Dispatch.invoke(excel, "ExportAsFixedFormat", Dispatch.Method,obj2, new int[1]);

        } catch (Exception es) {
            es.printStackTrace();
            throw es;
        } finally {
            if (excel != null) {
                Dispatch.call(excel, "Close", new Variant(false));
            }
            if (ax != null) {
                ax.invoke("Quit", new Variant[] {});
                ax = null;
            }
            ComThread.Release();
        }
	}
}
